1 - faraday - Eastern Mediterranean University 1
2
Name:
Number:
Date: 08 November 2012
3
4
EENG410/INFE410 - MICROPROCESSORS I
Midterm Exam
T
Instructor: Dr. Hasan Demirel
1. The duration of the exam is 90 minutes. No extra time will be given.
QUESTIONS
+SOLUTIONS
-----------------------------------------------------------------------------------------------------------------------------1. (%20) What will be the values of the specified registers and flags after the execution of the
following instructions?
a)
MOV
MOV
SHL
AX,9A3FH
CX,3603H
AX,CL
AX,CX
b)
AX=?, CX=?,
CF=?, PF=?, AF=?, SF=?, ZF=?
a)
MOV
MOV
SHL
AX,9A3FH
CX,3603H
AX,CL
AX,CX
MOV
MOV
INC
SUB
DL,63H
DH,DL
DH
DL,DH
DX,9B00H
DX=?
CF=?, PF=?, AF=?, SF=?, ZF=?
 AX=9A3FH (CF=? , AX=1001 1010 0011 1111B )
 CX=3603H
 CF= 0 , AX=1101 0001 1111 1000B AX= D1F8H
 AX= D1F8H + 3603H

D1F8H
1101 0001 1111 1000
+ 3603H
+0011 0110 0000 0011
07FBH (CF=1) 0000 0111 1111 1011
AX = 07FBH, CX=3603H, CF=1, PF=0, AF=0, SF= 0, ZF=0
b)
MOV
MOV
INC
SUB
DL,63H
DH,DL
DH
DL,DH
DX,9B00H





DL=63H
DL=DH=63H
DH=64H
DL=63H-64H= FFH, CF=1 (DX=64FFH)
DX= 64FFH + 9B00H

64FFH
0110 0100 1111 1111
+9B00H
1001 1011 0000 0000
+
1
+
1
0000H (CF=1) 0000 0000 0000 0000
DX = 0000H, CF=1, PF=1, AF= 1, SF=0, ZF=1
------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------2. (%25) Given a 32 bit number A in the data segment below, write an assembly language
program to:
a) set the MSB of A, reset the LSB of A and save it into B,
b) toggle the bits in the most significant nibble (MSN) and LSN of A and save it into C,
c) swap the most significant and the least significant bytes of A and save it into D.
Note that, you are required to write only one program in which you could include the data
segment given below.
.DATA
A
B
C
D
DD
DD
DD
DD
8F6E4937H
?
?
?
.MODEL SMALL
.STACK 64
.DATA
A DD 8F6E4937H
B DD ?
C DD ?
D DD ?
.CODE
MAIN:
MAX AX,@DATA
MOV DS,AX
MOV SI, OFFSET A
MOV DI, OFFSET B
MOV AX,[SI]
AND AX,1111111111111110B
MOV [DI],AX
MOV AX,[SI+2]
OR AX,1000000000000000B
MOV [DI+2],AX
; Choice (a) is until here.
MOV DI, OFFSET C
MOV AX,[SI]
XOR AX,0000000000001111B
MOV [DI],AX
MOV AX,[SI+2]
XOR AX,1111000000000000B
MOV [DI+2],AX
; Choice (b) is until here.
MOV DI, OFFSET D
MOV AL,[SI]
MOV AH,[SI+3]
MOV [DI],AH
MOV [DI+3],AL
MOV AL,[SI+1]
MOV [DI+1],AL
MOV AL,[SI+2]
MOV [DI+2],AL
; Choice (C) is until here.
MOV AH,4CH
INT 21H
END MAIN
-----------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------3.
(%25) Write an assembly language program that will process the given sentence as follows:
a) Toggle only the lower case letters to uppercase.
b) Count and save the number of letters changing case and number of characters
remaining unchanged.
Consider the following sentence in your program.
“Eastern Mediterranean University was established in 1979.”
The program should be general and work for any sentence ending with a full stop ‘.’ character.
Consider the following sentence in your program.
Hint: Uppercase characters are ordered between ‘A’ (41H) and ‘Z’ (5AH) and lowercase characters are ordered
between ‘a’ (61H) and ‘z’ (7AH) in the in the ASCII Code table. For lowercase letters, bit 5 (d5) of the ASCII code is
1 where for uppercase letters it is 0. For example,
Letter
‘h’
‘H’
Binary
01101000
01001000
ASCII
68H
48H
.MODEL SMALL
.STACK 64
.DATA
A DB ’Eastern Mediterranean University was established in 1979.’
B DB 57 DUP(?)
COUNT DB
?
.CODE
MAIN:
MAX AX,@DATA
MOV DS,AX
MOV DL,0 ; counter = 0
MOV SI, OFFSET A
MOV DI, OFFSET B
REPEAT: MOV AL,[SI]
CMP AL,’.’
JE EXIT
CMP AL,61H
JB OVER
CMP AL,7AH
JA OVER
XOR AL, 00100000B
INC DL
OVER: MOV [DI],AL
INC SI
INC DI
JMP REPEAT
EXIT: MOV COUNT,DL
MOV AH,4CH
INT 21H
END MAIN
------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------4. (%30) Shift instructions can be used to multiply and divide unsigned numbers. Given the
following two arrays (A and B), write an assembly language program to perform the necessary
operations to calculate the values in arrays C and D. Use suitable shift instructions to perform
the multiplication and division operations.
A= 46, 37, 77, 94, 64, 59
B= 2, 4, 8, 16, 32, 64
Ci  Ai Bi
Di  Ai / Bi
.MODEL SMALL
.STACK 64
.DATA
A
DB
B
DB
C
DW
D
DB
.CODE
MAIN:
MAX
MOV
MOV
MOV
MOV
MOV
MOV
BACK:
MOV
MOV
SHL
MOV
MOV
SHR
MOV
INC
INC
INC
INC
INC
DEC
JNZ
MOV
INT
END
i  1,, 6
46, 37, 77, 94, 64, 59
2, 4, 8, 16, 32, 64
6 DUP(?)
6 DUP(?)
AX,@DATA
DS,AX
CH,6
CL,1
SI, OFFSET
BX, OFFSET
DI, OFFSET
AH,00
AL,[SI]
AX,CL
[BX],AX
AL,[SI]
AL,CL
[DI],AL
SI
BX
BX
DI
CL
CH
BACK
AH,4CH
21H
MAIN
A
C
D
; save the multiplication
; save the division (ignore remainder)
------------------------------------------------------------------------------------------------------------------------------