Computer Architecture and Assembly Language Programming (CS401)

Computer Architecture and Assembly Language Programming (CS401)

Computer Architecture and Assembly Language Programming (CS401)

Assignment # 1

Total marks = 20

Deadline Date = November24, 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.

Topic Covered:

  • Introduction to Computer Architecture and Assembly Language Programming.
  • Addressing Modes.
  • Branching Techniques.

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:

Question No. 1:(10 marks)

We have the following register values:

AX = 420AH,

BX = A12EH,

DS = 22EAH,

CS = 0100H,

ES = 0FEAH,

SS = 0FE0H,

SI = 0010,

BP = 02ACH and

DI = 0300H.

You are required to calculate the physical address generated by each of the following instructions?

  1. mov [bx+si+di],ax
  2. ADD AX,[BP+12]

Note: Every instruction is independent of others.

Question No. 2:(10 marks)

  1. Assemble the given program using NASM.

[ORG 0X0100]

MOV CX, 5

XOR AX, AX

MOV BX, NUM

L1: ADD AX, [BX]

ADD BX, 2

SUB CX, 1

JNZ L1

MOV [SUM], AX

MOV AX, 0X4C00

INT 0X21

NUM: DW 0, 1, 2, 3, 4.

SUM: DW 0

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

Fig 1: Loading debugger.

  1. The AFD window will be opened. The complete description is given below in fig 2C Documents and Settings waqar ahmed My Documents My Pictures untitled JPG

Fig 2: AFD description.

  1. 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 and the registers are updated, how the instruction pointer moves forward.
  1. Now we execute the program with F2 key (instruction will move one by one) and write down the contents of the specified registers in the given table.

Instruction / Register current value after the instruction execution / IP
(Instruction Pointer) / Flags
OF / CF / ZF / PF / SF / AF
1 / [ORG 0X0100] / AX
BX
CX
DX
2 / MOV CX, 10 / AX
BX
CX
DX
3 / XOR AX, AX / AX
BX
CX
DX
4 / MOV BX, NUM / AX
BX
CX
DX
5 / ADD AX, [BX] / AX
BX
CX
DX
6 / ADD BX, 2 / AX
BX
CX
DX
7 / SUB CX, 1 / AX
BX
CX
DX
8 / JNZ L1 / AX
BX
CX
DX
9 / ADD AX, [BX] / AX
BX
CX
DX
10 / ADD BX, 2 / AX
BX
CX
DX
11 / SUB CX, 1 / AX
BX
CX
DX
12 / JNZ L1 / AX
BX
CX
DX
13 / ADD AX, [BX] / AX
BX
CX
DX
14 / ADD BX, 2 / AX
BX
CX
DX
15 / SUB CX, 1 / AX
BX
CX
DX
16 / JNZ L1 / AX
BX
CX
DX
17 / ADD AX, [BX] / AX
BX
CX
DX
18 / ADD BX, 2 / AX
BX
CX
DX
19 / SUB CX, 1 / AX
BX
CX
DX
20 / JNZ L1 / AX
BX
CX
DX
21 / ADD AX, [BX] / AX
BX
CX
DX
22 / ADD BX, 2 / AX
BX
CX
DX
23 / SUB CX, 1 / AX
BX
CX
DX
24 / JNZ L1 / AX
BX
CX
DX
25 / MOV [SUM], AX / AX
BX
CX
DX
26 / MOV AX, 0X4C00 / AX
BX
CX
DX
27 / INT 0X21 / AX
BX
CX
DX

Table: Register contents after the execution of each instruction.