Question no. 1:
Assuming the following Assembly language code, assemble it and at the end of each instruction, show the changed values ofALand the indicated FLAGS.
MOVAL, 8Bh AL=8B, CF = 0, SF = 0, PF = 0, ZF = 0;
ADDAL, 22h AL=AD, CF = 0, SF = 1, PF = 0, ZF = 0;
AND Al, 1000101b AL=05, CF = 0, SF = 0, PF = 1, ZF = 0;
OR Al, 9Ah AL=9F, CF = 0, SF = 1, PF = 1, ZF = 0;
XORAL, 10101011b AL=34, CF = 0, SF = 0, PF = 0, ZF = 0;
TEST AL, 2 AL=34, CF = 0, SF = 0, PF = 1, ZF = 1;
CMP AL, 58 AL=34, CF = 1, SF = 1, PF = 1, ZF = 0;
ADCAL, 11110000b AL=25, CF = 1, SF = 0, PF = 0, ZF = 0;
SHR AL,2 AL=09, CF = 0, SF = 0, PF = 1, ZF = 0;
Question no. 2:
Write a subroutine that can calculate the sum of an array, assuming that the array’s length is 20 and also save the end result in to DX.
Solution:
[org 0x0100]
MOV BX, ARRAY ;point BX towards the first element in ARRAY
MOV CX, 10 ;load count of numbers in cx
MOV AX, 0 ;initialize sum to zero
CALL ARRAY_SUM ;CALL the subroutine named as ARRAY_SUM
MOV AX, 0x4c00 ;terminate program
INT 0x21
ARRAY: DW 1,2,3,4,5,6,7,8,9,10 ;Array data
ARRAY_SUM: ADD AX,[BX] ;add the first element of an array to AX
ADD BX,2 ;Point BX towards the next element in ARRAY
DEC CX ;Decrement the Counter
JNZ ARRAY_SUM ;Loop(adding) until the end of the ARRAY
MOV DX, AX ;Store the end result into DX
RET ;return control to the main program
Question no. 3
Write an assembly language code to calculate the factorial of “7” using a subroutine.
Also attach the final snapshot of you AFD window.
Solution:
[org 0x0100]MOV AX,7 ;Move 7 to Accumulator
MOV CX,AX ;load count of numbers in cx
DEC CX ;Decrement CX
CALL FACTORIAL ;CALL the subroutine named as factorial
MOV AX, 0x4c00 ;terminate program
INT 0x21
FACTORIAL:
MOV BX,CX ;Move Multiplier to BX
MUL BX ;Perform multiplication AX = AX * BX
DEC CX ;Decrement the Counter
JNZ FACTORIAL ;Loop, constant multiplication until end
RET ;return control to the main program
/****************** Download Solution From here **********************\