Assembly Sample Programs
Assembly Sample Programs
Assembly Sample Programs
fno dW 250
sno dW 125
res dW ?
datasg ends
MOV AX,4C00H
INT 21H
CODESG ENDS
END
Q2:
data segment
MSG1 db 'WELCOME TO ASSEMBLY LANGUAGE PROGRAMMING',13,10,'$'
MSG2 DB 'AT INSDOC DELHI',13,10,'$'
data ends
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV AX,DATA
MOV DS,AX
LEA DX, MSG1 ;PRINT MESSAGE1
MOV AX,0900H
INT 21H
CODE ENDS
END
data segment
num dw 24h
lf equ 10
cr equ 13
;crlf db cr,lf,'$'
evenmsg db 'Number is even..',cr,lf,'$'
oddmsg db 'Number is odd..',cr,lf,'$'
data ends
code segment
assume ds:data, cs:code
oddnum:
mov dx, offset oddmsg
mov ah,09h
int 21h
mov ax,4c00h
int 21h
code ends
end start
question
data segment
password db 'failsafe'
deststr db 'feelsafe'
message db 'strings are equal'
data ends
code segment
assume cs:code,ds:data,es:data
code ends
end
Program : This program compares two strings and
; print message if two strings are not equal
data segment
password db 'failsafe'
deststr db 'feelsafe'
message db 'strings are equal'
data ends
code segment
assume cs:code,ds:data,es:data
code ends
end
data segment
numbers db 30h,35h,32h,31h,33h
largest db 00h,13,10,00h
data ends
code segment
assume ds:data,cs:code
mov ax,data
mov ds,ax
mov cx,05
mov si,offset numbers
lea di,largest
mov al,[si]
mov byte ptr [di],al
c20:
mov al,[si]
cmp al,largest
jg replaceval
inc si
loop c20
jmp printit
replaceval:
mov byte ptr [di],al
inc si
jmp c20
printit:
mov ah,09h
mov dx, offset largest
int 21h
exit_to_dos:
mov ax,4c00h
int 21h
code ends
end
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV AX,DATA
MOV DS,AX
MAIN PROC
CALL REVERSEDATA
CALL PRINTIT
MOV AX,4C00H
INT 21H
MAIN ENDP
REVERSEDATA PROC
CLD
LEA SI,STR1
LEA DI,STR2+11 ;LOAD ADDRESS OF THE LAST CHARACTER
MOV CX,12
B20:
LODSB ;AL <- FIRST CHARACTR OF THE STRING
MOV [DI],AL ;MOVES FIRST CHARACTER OF STR1
;AS A LAST CHARACTER OF STR2
DEC DI
LOOP B20 ;IF COUNTER IS NOT ZERO THEN LOOP
;ELSE
RET ;RETURN
REVERSEDATA ENDP
PRINTIT PROC
CODE ENDS
END
Que: Takes two multi digit number as input from keyboard and add it
STACK SEGMENT
DW 32 DUP(0)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV AX,DATA
MOV DS,AX
MOV AH,0AH
MOV DX, OFFSET BUFFER
INT 21H
;;***** STORE THE ACCEPTED VALUE TO THE VARIABLE ASC1
LOOP L1
MOV AH,0AH
MOV DX, OFFSET BUFFER
INT 21H
;;***** STORE THE ACCEPTED VALUE TO THE VARIABLE ASC2
LEA SI, BUFFER+2
LEA DI, ASC2
MOV CX, 0500H ;;IN SECOND BYTE OF THE BUFFER ACTUAL LENGH
IS STORED
REP MOVSB
A20:
MOV AH,00 ; HIGHER BITS ARE LOADED WITH ZEROS AND
MOV AL,[SI] ; LOWER BITS WITH DIGIT OF FIRST NUMBER
ADC AL,[DI] ; ADD ONE DIGIT OF FISRT NUMBER
; WITH ONE DIGIT OF SECOND NUMBER ALONG WITH
CARRY
AAA ;ADJUST ASCII NUMBER ie. SUM
MOV AX,0900H
LEA DX,ASCSUM
INT 21H
MOV AX,4C00H
INT 21H
CODE ENDS
DATA SEGMENT
ASC1 DB '00000'
ASC2 DB '00000'
ASCSUM DB '0000000',13,10,'$'
buffer db 6
db 00
db 5 dup(0),'$'
DATA ENDS
END
data segment
asc1 db '057836'
asc2 db '069427'
bcd1 db '000'
bcd2 db '000'
bcdsum db '00000000',13,10,'$'
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
MOV AX,DATA
MOV DS,AX
main proc near
LEA SI, ASC1+4 ;initialize for ascii
LEA DI, BCD1+2
CALL ASC2BCD
LEA SI,ASC2+4
LEA DI, BCD2+2
CALL ASC2BCD
CALL ADDBCD
MOV AX,0900H
MOV DX, OFFSET BCDSUM
INT 21H
MOV AX,4C00H
INT 21H
MAIN ENDP
ASC2BCD PROC
MOV CL,04 ;SHIFT FACTOR
MOV DX,3 ;NO OF WORDS TO CONVERT
ADDBCD PROC
XOR AH,AH ;CLEAR AH
LEA SI,BCD1+2 ;INITIALIZE
LEA DI,BCD2+2 ; BCD ADDRESSES
LEA BX,BCDSUM+3
MOV CX,03 ;3-BYTE FIELDS
CLC
ADD20:
MOV AL,[SI] ;GET BCD1 (or LOADSB)
ADC AL,[DI] ;ADD BCD2
DAA ;DECIMAL ADJUST
MOV [BX],AL ; STORE IN BCDSUM
DEC SI
DEC DI
DEC BX
LOOP ADD20 ; LOOP 3 TIMES (AS THERE ARE 3 IN CX)
RET
ADDBCD ENDP