CS401 VU Assignment No. 2 Spring 2012 Solution

Question no. 1:

(a) Assemble the following instructions and show the changes in given Accumulator register and flags after each instruction execution. (Marks 5)

MOV AL, 8Bh ; CF = 0, SF = 0, PF = 0, ZF = 0

ADD AL, 22h ; CF = 0, SF = 0, PF = 0, ZF = 0

AND Al, 1000101b ; CF = 0, SF =1 PF = 0, ZF = 0

OR Al, 9Ah ; CF = 0, SF = 0, PF = 1, ZF = 0

XOR AL, 10101011b ; CF = 0, SF = 1, PF = 1, ZF = 0

TEST AL, 2 ; CF = 0, SF = 0, PF = 0, ZF = 0

CMP AL, 58 ; CF = 0, SF = 0, PF = 1, ZF = 1

ADC AL, 11110000b ; CF = 1, SF = 1, PF = 1, ZF = 0

SHR AL,2 ; CF = 1, SF = 0, PF = 0, ZF = 0

Question no. 1 (b): (Marks 5)

Write a subroutine that can calculate the sum of an array and also save the result into DX.
( Array’s length is 20)
 


 
[org 0x100]

mov bx,[num1] ;pointing bx to first num means (15)

mov cx, 8     ; load count of numbers in cx means total numbers are 8

l1:

add ax, [bx]  ; add number to ax bx=15 so now ax=15

add bx, 2     ; advance bx to next number

sub cx, 1     ; numbers to be added reduced

jnz l1        ; if number is remain there then jump tto l1

mov [total], ax ; write sum in memory

mov ax, 0x4c00

int 0x21

num1: dw 15, 20, 25, 30, 35, 40, 45, 50

total: dw 0

Question no. 2

Write an assembly language code to calculate the factorial of “7” using a subroutine and also attach the final snapshot of your AFD window.


CS401 Assignment solution

DOWNLOAD SOLUTION HERE
loading...