0% found this document useful (0 votes)
14 views6 pages

M I Sample Test Solution

This document contains a sample test solution for a course at the Addis Ababa Institute of Technology, focusing on topics related to assembly language and computer architecture. It includes various questions and answers regarding physical and logical addresses, instruction execution, flags, and code snippets. The document also provides code examples and explanations of assembly language operations and their outcomes.

Uploaded by

Gelantu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views6 pages

M I Sample Test Solution

This document contains a sample test solution for a course at the Addis Ababa Institute of Technology, focusing on topics related to assembly language and computer architecture. It includes various questions and answers regarding physical and logical addresses, instruction execution, flags, and code snippets. The document also provides code examples and explanations of assembly language operations and their outcomes.

Uploaded by

Gelantu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

                      

Addis Ababa Institute of Technology

School of Electrical and Computer Engineering

Sample Test Solution

1. The physical address corresponding to the logical address CS:IP = 1200:124F is 1324F (4 pts)
2. The processor fetches instruction pointed by IP from code segment of the RAM. (2 pts)
3. Programs in code segment & stack segment never write over each other, they are located at opposite ends
of the RAM. (3 pts)
4. Can a single physical address belong to many different logical addresses? (Yes, No) Yes (2 pts)
5. For the code bellow
MOV AX, 4234H
MOV [1200], AX
If little endian convention is being used, what will the content at the following offset address be? (5 pts)
1200: 34 1201: 42
6. Which of the instructions are erroneous or illegal (underline your choices) (3 pts)
MOV DX,CX MOV DS,DX
MOV AL,DX MOV DS,123H
7. Which of the following flags control the operation of instructions before they are executed, unlike
Conditional Flags which indicate some condition resulting after an execution. (3 pts) DF IF TF

8. Overflow flag is used only to detect errors in signed arithmetic operations. (2 pts)
9. What do you think will the values of the flags SF, OF and CF be after the following signed number
arithmetic? (assume that the 8th bit represents sign in this question) SF= 1 , OF= 1 and CF 0
(5 pts)
MOV AL, 7FH
ADD AL, 01H
10. Fill the following table to show default segment for all of the six offset registers. (3 pts)

11. Given SP=111EH & BX=0010H, what will be the value of registers AX and SP After execution of the following
instructions? (5 pts)

1|
MOV AX, 441AH
MOV [BX], AX
ADD AX, 2
MOV [BX] + 2, AX
PUSH AX AX = 0010
PUSH BX
POP AX SP= 111C

12. For the jump instruction bellow, determine the value of XXXXH. (5 pts)

Machine Code Corresponding assembly code XXXXH = 00F1H


1110:0100 75F1 JNZ XXXXH

13. The following code operates on a net income received from the user and saved in register AX. Rewrite the
code using if-else statement. (Ignore the comments) (10 pts)

ADD AX, 0H
JNS option1 ;Jump if result is non negative
.... ; body to display "You are on Loss" text
If ( result < 0)
JMP END ;unconditional jump //display "You are on Loss"
Option1: else if ( result == 0 )
JNZ option2 ; jump if result is not zero // display " You are on Breakeven"
.... ; body to " You are on Breakeven" text Else
// display "You made a Profit"
JMP END ;unconditional jump
Option2:
.... ;body to display "You made a Profit" text
END:

14. The following code operates on a 16 bit number stored in variable NUM. After execution of the code what
does the value stored in COUNT represent? (10 pts)

MOV CX,16 ;loop through 16 bits (1 word)


CLC ; clear carry flag
SUB BX,BX ;
MOV AX,NUM ;load number into AX
BACK: SHR AX,1
JC END_LOOP ;if CF=1, don't increment count
INC BX ;
END_LOOP: LOOP BACK
MOV COUNT,BX

Answer: Value stored in COUNT represents number of zero digits in binary representation of NUM

2|
15. For the following two code fragments underline the value of the two flags, ZF & CF. (6 pts)

ZF CF
a MOV BL, 0FFH
CMP BL,6FH 1 / 0 1 / 0
b XOR BL, BL
CMP BL,0FFH 1 / 0 1 / 0

16. Show the 3 steps involved in the following (6 pts) 17. Write a 4 -line code that multiplies the
following two 1-word numbers and saves the
MOV BH, 1AH result in these already defined variables,
MOV AL,6FH Num1 & Num2. (6 pts)
SUB AL,BH
Num1 = 154AH
Step 1: Num2 = 247FH
2's complement of the subtrahend
( 00011010 )’ +1 Line1: MOV AX,Num1
= 11100101 +1
Line2: MUL Num2
= 11100110
Step 2: Line3: MOV Num2,DX
Add it to the minuend
Line4: MOV Num1,AX
01101111
11100110 +
= 1 01010101
Step 3:
Invert the carry
CF=0

18. What does the following codes do? (5 pts each)

a. b. c.
MOV AH,02 MOV AH,09 AGAIN:
MOV BH,00 MOV DX,OFFSET DATAIN MOV AH,00
MOV DL,25 INT 21H INT 16H
MOV DH,15 MOV AH,02
INT 10H MOV DL,AL
INT 21H
JMP AGAIN
Moves the cursor to 25,15 on Displays ASCII data string contained in Read a character from the
the dos screen DATAIN to the monitor (DOS screen) keyboard and display to
Monitor (DOS screen)

3|
19. Write an assembly code fragment that detects character sequence “abc” and prints the text “BINGO” to
the DOS screen whenever the sequence is detected in a loop fashion. (15 pts)
*Hint: You may use appropriate interrupts from question # 18 to read characters and display string.

Int state=0
while (true)
{
key=getchar
if(state==0 & key==a)
state++
else if(state==1& key==b)
state++
else if(state==2 & key==’c’)
{
display BINGO
state=0
}
else
state=0
}

Putting the problem in if else statement pseudo code makes it easier to understand and assembly codding.
Now you start from the inner condition (if state ==2) and go to the outer (refer option 1).
Note that you can implement this in many other ways.

4|
; Option 2
; Option 1 ; Option 3
org 100h
org 100h org 100h
.DATA
.DATA .DATA
BUFFER DB 'BINGO','$'
BUFFER DB 'BINGO','$' BUFFER DB 'BINGO','$'
DATA DB 'abc','$'
.CODE .CODE
.CODE
MOV CX,0 AGAIN:
Reset:
AGAIN: MOV AH,01
MOV CX,3
MOV AH,01 INT 21H
MOV BX, OFFSET DATA
INT 21H CMP AL,'a'
AGAIN:
CMP CX,2 JNZ AGAIN
MOV AH,01
JNZ state2 MOV AH,01
INT 21H
CMP AL,'c' INT 21H
CMP AL,[BX]
JNZ state0 CMP AL,'b'
JZ NextState
MOV AH,09 ;need to add few lines to
JMP Reset
MOV DX,OFFSET BUFFER ; handle 'a' input at this state
;need to add few lines to
INT 21H ; E.g. ‘aabc’
; handle multiple 'a' inputs
JMP state0 JNZ AGAIN ;
; E.g. ‘aabc’
state2: MOV AH,01
CMP CX,1 INT 21H
NextState:
JNZ state1 CMP AL,'c'
INC BX
CMP AL,'b' JNZ AGAIN
DEC CX
JNZ state0 MOV AH,09
JNZ AGAIN
INC CX MOV DX, OFFSET BUFFER
MOV AH,09
JMP AGAIN INT 21H
MOV DX,OFFSET BUFFER
state1: JMP AGAIN
INT 21H
CMP AL,'a'
JMP Reset
JNZ state0
INC CX
JMP AGAIN
state0:
MOV CX,0
JMP AGAIN

5|
20. Discuss the difference between the x86 and ARM instruction sets in general.

For each of the following questions and sub questions, unless stated otherwise, assume the ARM
instruction set (32 bit instruction) and that every memory location is initialized with its address minus 1
Memory Address Value
… …
0x200 0x1FF
0x201 0x200
0x202 0x201
…. ….

21. If r1=0x200 & r2=0x10, what will be the value of r0 and r1 after execution of the following instructions?
Assumption applies on each instruction individually.

a. MOV r0, #0x8f, 8 r0=0x8F00, r1=0x10


b. LDR r0,[r1,-r2,LSL#2] r0=0x1BF, r1=0x10
c. LDR r0,[r1,#8] r0=0x207, r1=0x10
d. STR r2,[r1],#20 r0=----, r1=0x220
e. LDR r0,[r1,#10]! r0=20F, r1=0x210

22. Write the equivalent assembly code for the following C codes, ignore variable to register association code:
for(i=0;i<10,i++
int *ptr; if (a==4 && a==10) {
y=a*8
x = *ptr++; x=0; a+=func(i)
}

LDR r0, [r1], #4 CMP r0,#4 MOV r0, r1, LSR #3 SUB r0,r0,r0
CMPEQ r0,#10 SUB r2,r2,r2
MOVEQ r1,#0 CMP r0,#10
Loop BLLT func
;func can access r0 (i)
;and store return on r1
ADDLT r2, r2,r1
BLT Loop

6|

You might also like