Developed By: Sujit Jhare Assembly Language Programming
Developed By: Sujit Jhare Assembly Language Programming
Arithmetic operation:
; REGISTER : AX BX
; PORT : no uses
CODE SEGMENT
END CODE
LDA 2200H
CMA
STA 2300H
HLT
cma will give 1's complement of a number
LDA 2200H
CMA
ADI 01H
STA 2300H
HLT
Object: program to read ASCII code after a strobe signal is sent from keyboard
CODE SEGMENT
CODE END
END
Object: program adds and inflation factor to a series of prices in memory, it copies
the new prices over the old price.
ARRAY SEGMENT
ARRAY END
CODE SEGMENT
CODE END
END START
MOV SI,2000
MOV DI,4000
MOV CX,0001
MOV BX,0000
MOV AL,[SI] ; Load AL with the value given as at SI
UP SUB AL,CL
JL down ; jump to down label
INC BL
ADD CL,02 ; add 2 to contents of CL register
JMP UP ; jump to up label
DOWN MOV[DI],BL
INT A5
Program to perform sum of elements in an array
Following is the assembly language program to find the sum of elements in a given
array. This code is for 16-bit addition with 64 stack size.
Code:
ORG 2000H
LXI H,2100H ;DATAS ARE STORED AT LOCATIONS 2100H,21001H
MOV A,M
MVI C,07H
LOOP: RRC
CALL SBR ;SBR IS SUBROUTINE
DCR C
JNZ LOOP
ANI 01H
ADD D
INX H
CMP M
LXI H,2400H ;1 IS STORED AT MEM-LOC 2400H IF PALIIN ELSE 0
JZ PALIN
MVI M,00H
JMP FIN
ORG 2100H
DB 00C7H,00EBH ;DATA BYTE
END
here EBH is reversed and compared with C7H, if they are equal then plain else not
palin
LDA 2200H
CMA
STA 2300H
HLT
cma will give 1's complement of a number
LDA 2200H
CMA
ADI 01H
STA 2300H
HLT
here first the once's complent of the number is determined and then one is added to it
LDA 2200H
MOV C,A
LXI H,2201H
SUB A
MOV B,A
Back: ADD M
JNC Skip
INR B
skip INX H
DCR C
JNZ BACK
STA 2300H
MOV A,B
STA 2301H
HLT
This program will add tho hexa deciaml numbers without carry
How to add two Hexa decimal numbers without carry
LDA 2200
MOV C,A
SUB A
LXI H,2201H
Back: ADDM
INT H
DCR C
JNZ Back
STA 2300H
HLT
lnitialize counter c
then make sum=0
initialize the pointer
sum = sum+data
decrement counter c
if counter is zero then repeat else
store the result
halt the program.
Code:
Initially the input is moved in SI register , then its divided by 10 and then 30 is added
to the number for both AH, AL i.e. the 8 bit higher and lower registers. Then the
output is moved to the destination index register.
Following is the program code in assembly language to convert a BCD number to ASCII.
MOV SI,2000
MOV DI,4000
MOV AX,[SI]
MOV BL,10
DIV BL
MOV DL,30
ADD AL,DL
ADD AH,DL
MOV [DI],AX
INT A5
MOV SI , 2000
MOV DI,2002
MOV CX,[SI]
MOV AX,CX ; Move contents of CX to contents of AX register
DEC CX ; Decrement CX
UP: MUL CX
DEC CX ; Decrement CX
JNZ; UP ; Jump if not zero
MOV [DI], AX ; Load the values of AX into location given by DI
INT A5; Halt the program
The program to find out the largest number from an unordered array of sixteen 8 bit
numbers stored sequentially in the memory locations starting at offset 0500H in the
segment 2000H
Logic: The 1st number of the array is taken in a register, say AL. The 2nd number of
array is then compared with the 1st one. If the 1st one is greater than 2nd one, it is
left unchanged. However, if the 2nd one is greater than 1st, 2nd number replaces the
1st one in the AL register. The procedure is repeated for every number in array and
thus requires 15 iterations.
following is the assembly language program for push and pop operations in a stack.
code segment
main:
mov sp,1000h initialize SP to point to stack
mov ax,1234h
mov bx,5678h
mov cx,9abcdh
push ax
push cx
pop ax
pop ax
pop bx
pop cx
mov bx,0200h
mov w[bxx],1234h; address 0200 holds 1234
push [0200h]
push[bx]
mov bx,0210h
pop [bx]
pop[0212h]
imp main ; demo again
code ends