loading...

CS401 Assembly Language Assignment 2 Solution Fall 2012

Question No. 1:

Assemble the given Subroutine program using NASM (Netwide Assembler) to add 10 numbers array using a subroutine named as “sumofarray” and show the changes occurs in AX, BX & CX on each step.                                                                                             (10 marks)

                                                                                                                                                          

[ORG 0x0100]

 MOV BX, VAL        

MOV CX, 3  

MOV AX, 0                 

CALL SUMOFARRAY 

MOV AX, 0X4C00  

INT 0X21

 SUMOFARRAY:     ADD AX, [BX]         

ADD BX, 2   

SUB CX, 1                

JNZ SUMOFARRAY                                 

MOV [SUM], AX     

RET

 VAL: DW 30,40,50

SUM: DW 0

 

Note: Execute this program with F2 key (instruction will move one by one) and using F1 key is used to trace the call subroutine. Write down the contents of the specified registers in the given table.

 

Instruction

Registercurrent value after the instruction execution

IP

(InstructionPointer)

Flags

CF

ZF

PF

SF

AF

1 [ORG 0x0100] AX
BX
CX
2 MOV BX, VAL AX  

 

 

 

BX
CX
3 MOV CX, 3 AX
BX
CX
4 MOV AX, 0 AX
BX
CX
5 CALL SUMOFARRAY
6 MOV AX, 0X4C00
7 INT 0X21
8  

SUMOFARRAY:

 

 

ADD AX, [BX]

AX
BX
CX
ADD BX, 2 AX
BX
CX
SUB CX, 1 AX
BX
CX
9  

SUMOFARRAY:

 

ADD AX, [BX]

AX  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

BX
CX
ADD BX,2 AX
BX
CX
 

SUB CX,1

AX
BX
CX
 

10

 

SUMOFARRAY:

 

 

ADD AX, [BX]

 

AX
BX
CX
ADD BX,2 AX
BX
CX

 

SUB CX,1 AX
BX
CX
11 MOV [SUM], AX AX
BX
CX

 Solution:

 

 

 

Question No. 2:

After attempting previous question, u are now able to write, assemble and debug a Subroutine program.  Write an assembly language code to find the minimum number from an array of ten numbers using a subroutine. Explain each instruction of program in your own words and also attach the snapshot of your AFD (A Fullscreen Debugger) showing the executed code of final results.                                                                                            

                                                                                                                             (10 marks)

 

(Program using subroutine: 5 marks, Explanation: 3 marks, Snapshot: 2 marks)

 

Array of 10 numbers:

 

Found the minimum and stored in memory location from CX register

DOWNLOAD SOLUTION HERE
loading...