0% found this document useful (0 votes)
40 views18 pages

Aim: Write A Program Which Sets The Parity Bit. Code

The document contains 11 assembly language programs with the following objectives: 1. Set the parity bit of a number and transfer flags to a register. 2. Add two hex numbers and store the sum and flags. 3. Add two numbers using a subroutine and clear the zero flag. 4. Set and reset the zero flag over iterations. 5. Reverse a string using stack operations. 6. Calculate the sum of even numbers from a list. 7. Arrange an array in ascending order. 8. Fill memory with Fibonacci numbers.

Uploaded by

Samin Momin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views18 pages

Aim: Write A Program Which Sets The Parity Bit. Code

The document contains 11 assembly language programs with the following objectives: 1. Set the parity bit of a number and transfer flags to a register. 2. Add two hex numbers and store the sum and flags. 3. Add two numbers using a subroutine and clear the zero flag. 4. Set and reset the zero flag over iterations. 5. Reverse a string using stack operations. 6. Calculate the sum of even numbers from a list. 7. Arrange an array in ascending order. 8. Fill memory with Fibonacci numbers.

Uploaded by

Samin Momin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Microprocessor Architecture and Assembly Programming (CE341) 17CE058

EXPERIMENT-5
Program-1
Aim: Write a program which sets the parity bit.

Code:
.model prac5_1

.data
number dB 00000000b

.code
mov ax,@data ;base address
mov ds,ax ; moving to base address
MOV ah,number; it will move parity bit to all
sahf;register to flag

Output:

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 1


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

Program-2
Aim: Write a program which transfers content of Flags to Register

Code:

.model prac5_2

.data
number dB 1010101b;

.code
mov ax,@data ; base address
mov ds,ax ; moving to base address
MOV ah,number;storing value at ah register
sahf;register to flag
mov ah,0;storing value 0 at ah register
lahf ; flag to register

Output:

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 2


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

Program-3
Aim: Write a program to add the two Hex Numbers 7AH and 46H and to store the sum at
memory location 2098 and flags status at 2097 location.

Code:
.model prac5_3

.data
num1 db 7ah;num1=7ah
num2 db 46h;num2=46h

.code
mov ax,@data; base address
mov ds,ax; moving to base address
mov bh,num1;moving value of num1 to bh register
adc bh,num2; adding num1 and num2 with carry
lahf; flag to fregister

mov dh,ah; moving values of ah to dh register


mov cx,200h; base address at 200
mov ds,cx ; moving to base location at 2000h
mov [098h],bh;moving value of bh register to 2098 location
mov [097h],dh;moving value of dh register to 2097 location

end

Output:

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 3


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 4


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

Program-5
Aim: Using a Subroutine, write a program which adds two hex number 10H and F0H and
store result at 2040H location in memory. At the end of subroutine, clear the flag Z without
affecting other flags and return to main program.

Code:
.model prac5-5

.data
a dw 10h;a=10h

b dw 00f0h;b=00f0h

.code

mov bx,@data;base address


mov ds,bx;moving to base address

mov ax,a; moving value of a to ax register

adc ax,b;adding a and b with carry


call addition; subroutine call

addition proc; procedure starts

mov bx,200h;base address


mov ds,bx;moving to base address

mov [0040h],ax;moving result of ax to location at 2040h


lahf

and ah,10111111b;performs and operations


sahf

endp;end of procedure

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 5


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

end

Output:

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 6


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

Program-6
Aim:. Write a program which set and resets zero flag at next iteration. (take number of
iteration equal to 5)
Code:
.model prac5.6

.data
.code

mov dh,4;dh=4
mov cx,5;counter =5

mov bl,2;bl=2 and it will be used for checking

checking:
mov al,dh;moving value of dh to al

div bl
cmp ah,2;comparing ah with 0
jz set

jnz reset;

set:
lahf

and ah,11111111b; it will set


sahf

jmp exit

reset:
lahf
and ah,10111111b;it will unset

sahf

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 7


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

exit:
inc dh

loop checking
end

Output:

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 8


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

Program-8
Aim: Implement a program to reverse a string using stack operations and stored in
same memory area
Code:
.model prac5-8

.stack 100h
.data

string db 'hinel', '^'


.code

mov ax,@data;base address


mov ds,ax;moving to base address

call rev;procedure call


; load address of the string

lea dx,string
; interrupt to exit
mov ah, 4ch

int 21h
rev proc

mov si, offset string


mov cx, 0h

checkloop:
;this check loop will decide if the character is last or not

mov ax, [si]


cmp al, '^'

je lastsymbol
;if it is not the $ symbol then do this
push [si]

;increament both cx and si


inc si

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 9


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

inc cx
jmp checkloop

lastsymbol:
;if jump is done then come here and set si again

mov si, offset string


reversing:

;if count is zero exit


cmp cx,0

je exit
; if not then execute

pop dx
; this is done becaue the values is only stored in dl and dh value is garbage so we need
want it

xor dh, dh
;this will help in reversing string
mov [si], dx

;decrementing cx
inc si

dec cx
jmp reversing

exit:
; add ^ to the end of string

mov [si],'^ '


ret

rev endp
end

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 10


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

Output:

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 11


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

Program-9
Aim: Calculate the sum of series of even numbers from the list of numbers. The length
of the list is in memory location 2200H and the series itself begins from memory location
2201H. Assume the sum to be 8 bit number so you can ignore carries and store the sum
at memory location 2210H.
Code:
.model prac5-9
.data

.code
mov bx,200h;base address

mov ds,bx;moving to base address


mov bx,5;counter=5

mov [200h],bx
mov di,201h;first memory
mov bx,0;This will be used for zero flag

mov [222h],bx
mov bx,3;This is random value

mov cx,5
give:

mov [di],bx
inc bx

inc di
loop give

mov di,201h;This will start from first


mov cx,5
checking:

mov bl,2;This will check even numbers


mov al,[di]

mov dh,[di]

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 12


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

div bl
cmp ah,[222h]

jz addition
jnz end;This will do nothing

addition:
add [210h],dh;This will act as addition

jmp end
end:

inc di
loop checking

end

Output:

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 13


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

Program-10
Aim: Write an assembly language program to arrange an array of 10 data in ascending
order. The length of the list is in memory location 2200H and the series itself begins
from memory location 2201
Code:
.model prac5-10
.data

.code
mov bx,200h;base address
mov ds,bx;moving to base address

mov di,201h;This will be first memory


mov bx,20;This is random value

mov cx,10;counter=10
giving:

mov [di],bx
dec bx

inc di
loop giving

mov di,201h;This will start from first


mov bx,201h;This will start from second
mov cx,5

outerloop:
innerloop:

mov ah,[di]
mov dh,[bx]

cmp dh,ah;This will help in comparision


jc change

jnc exit
change:
mov dh,[bx]

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 14


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

mov [bx],ah;This will shift bigger number


mov [di],dh;This will shift smaller number

exit:
mov si,205h;This will help in comparison

cmp si,bx
jz abc

inc bx
jmp innerloop

abc:
inc di;This will be done for second element

mov bx,di
inc bx;
mov si,205h

cmp si,di
jnz outerloop

end

Output:

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 15


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

Program-11
Aim: Write an assembly language program to fill the memory locations starting from
3000h, with n Fibonacci numbers
Code:
.model prac5-11

.data
.code

mov bx,300h;base address


mov ds,bx;moving to base address

mov di,00h;di=0
mov cx,5;cx=5

mov [di],0;first element


mov [di+1],1;second element

fibo:
mov ax,[di]
mov bx,[di+1];third element

adc ax,bx;perform add with carry


mov [di+2],ax

inc di;shift by 2
loop fibo

end

Output:

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 16


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 17


Microprocessor Architecture and Assembly Programming (CE341) 17CE058

U & P U. Patel Department of Computer Engineering, CSPIT, CHARUSAT Page | 5. 10

You might also like