Sei sulla pagina 1di 5

Computer Architecture and Assembly Language Programming

(CS401)
Assignment # 1(Non-Graded)
Total marks = 20
Deadline Date = May 05, 2014

Please carefully read the following instructions before attempting assignment.

Rules for Marking


It should be clear that your assignment would not get any credit if:

The assignment is submitted after the due date.


The submitted assignment does not open or file is corrupt.
Strict action will be taken if submitted solution is copied from any other student or
from the internet.

1) You should concern recommended books to clarify your concepts as handouts are not
sufficient.
2) You are supposed to submit your assignment in .doc format. Any other formats like scan
images, PDF, zip, rar, bmp etc will not be accepted.

Note:
No assignment will be accepted after the due date via email in any case (whether it is the case
of load shedding or internet malfunctioning etc.). Hence refrain from uploading assignment in
the last hour of deadline. It is recommended to upload solution file at least two days before its
closing date.
For any query, feel free to email at:
cs401@vu.edu.pk

Question No. 1:
Suppose we have the following register values:
AX = 0200h
BX = 4336h
CX = 1234h
SI = 0100h
CS = 0FE0h and
DS = E000h
You are required to calculate the physical address generated by each of the following
instructions:
1. MOV AX, [CS: BX + 100]
2. MOV CX, [BX + SI + 0x0030]
Note: Every instruction is independent of others.
Solution:
1. MOV AX, [CS:BX + 100]
The effective address will be calculated by adding the value of BX and decimal 100.
Hexadecimal representation of 100 is 64h.
Effective address (E.A)

Physical Address

= BX + 64h
= 4336h + 64h
= 439Ah

= CS x 10h + EA
= 0FE0h x 10h + 439Ah
= 0FE00h + 439Ah
= 1419Ah

2. MOV CX, [BX + SI + 0x0030]


The effective address will be calculated by adding the values of BX, SI and 0x0030.
Effective address (E.A)

= BX + SI + 0x0030
= 4336h + 0100h + 0x0030
= 4466h

Physical Address

= DS x 10h + EA
= E000h x 10h + 4466h
= E0000h + 4466h
= E4466h

Question No. 2:
Assemble the given program using NASM.
ORG 0100H
XOR AX, AX
MOV BX, 55H
MOV AX, 42
ADD AX, BX
SUB BX, 02H
ADD AX, BX
SUB AX, EA12H
MOV BX, 22H
MOV AX, 0X4C00
INT 0X21

1. After that load the Debugger by typing AFD in command prompt as in Fig 1.

Fig 1: Loading debugger.

2. The AFD window will be opened. The complete description is given below in fig 2

Fig 2: AFD description.


3. When the program is loaded in the debugger, it is loaded at offset 0100, which
displaces all memory accesses in our program. Execute the program step by step and
examine how the memory is read, the registers are updated and how the instruction
pointer moves forward.
Solution:
Instruction
1

ORG 0100H

XOR AX, AX

MOV BX, 55H

MOV AX, 42

ADD AX, BX

SUB BX, 02H

ADD AX, BX

SUB AX, 10h

Register current
value after the
instruction
execution
AX
0000
BX
0000
AX
0000
BX
0000
AX
0000
BX
0055
AX
002A
BX
0055
AX
007F
BX
0055
AX
007F
BX
0053
AX
00D2
BX
0053
AX
00C2

Flags

IP
(Instruction
Pointer)
0100

CF

ZF

PF

SF

AF

0102

0105

0108

010A

010E

0110

0113

1 MOV BX, 22H


0
11 MOV AX, 0X4C00

BX
AX
BX
AX
BX

0053
00C2
0022
4C00
0022

0116

0119

Table: Register contents after the execution of each instruction.

Potrebbero piacerti anche