Beruflich Dokumente
Kultur Dokumente
BILKENT UNIVERSITY
Electrical and Electronics Engineering Dept.
EEE212 Microprocessors
SECTIONS 1-5 Midterm
Closed Book No Calculators
All programs need to be in assembly language!
Use the boxes provided for your answers!
Duration: 2 hours
Surname:_______________________________________
Name:_________________________________________
Signature:_______________________________________
Q1 (25 points)
Q2 (25 points)
Q3 (25 points)
Q4 (25 points)
TOTAL
Q1) [25 pts] a) [3 pts] Represent -2668 decimal in 32 bit signed arithmetic as a hex value
c) [7 pts] Consider the following program. At ROM address 07FFh, we are to jump to HERE1 or
HERE2 or HERE3. For each of the three cases, show which type of jump instructions (LJMP,
SJMP, or AJMP) can be used and which one(s) is to be preferred? Explain. Hint. AJMP uses
absolute addressing as in ACALL.
Jump to Location What is What is (are) Explanation for what is possible and what
possible preferred is preferred
HERE1 AJMP,LJMP AJMP Takes less code space, 2 bytes vs 3 bytes
DIV AB
SUBB The subtract with borrow instruction subtracts the byte variable and the contents of the carry
from the accumulator, placing the result in the accumulator. The carry flag serves as a "Borrow
Required" flag during the subtraction; when a greater value is subtracted from a lesser value (eg, 1 - 6),
this requires a borrow, so the carry flag is set. On all other conditions, the carry flag is cleared.
SUBB A, R0 ;register, A = A - R0 - C
SUBB A, #23h
SUBB A, @R1
SUBB A, P0
ORG 0H
CLR PSW.3
CLR PSW.4
MOV 40H, #0D9H
MOV 41H, #9AH
MOV 42H, #12H
MOV R0, #40H
MOV R2, #3
MOV R3, #29
CLR A
ORG 0H;
INTERNAL RAM BIT ADDRESSABLE RAM
MOV P1,#0FFH;
MOV A, P1; 00 00
PUSH 0E0H; 08 08
10 10
MOV R0, #11H; 18 18
MOV A, R0; 20 20
28 28
PUSH 0E0H; 30 30
SETB RS1; 38 38
POP 10H; 40 40
48 48
POP 11H; 50 50
MOV A,@R0; 58 58
60 60
CPL A; 68 68
ANL P1,#55H; 70 70
MOV P2,A; 78 78
...
MOV SP, #2FH; 90
PUSH 0E0H; A0
E0
PUSH 0A0H;
PUSH 90H;
P1, P2, A have RAM addresses of 90H, A0H, and E0H
MOV C,ACC.0; respectively.
MOV 00H,C;
+5V
MOV C,ACC.2; 74LS244
MOV C,ACC.7;
MOV 02H,C;
JNC NUM;
CPL A;
ANL A,#7FH;
NUM: MOV P2,A;
SJMP $;
A B C D E F G DP
GND
Q5) [25 pts] Please read this information carefully before starting the question.
Macro definitions: (extensions to instruction sets)
Macros are useful for code that is used repetitively throughout the program. It saves the
programmer the time and tedium of having to specify the code every time it is used.
The code is written only once in the macro definition and it can be used anywhere in the source
program any number of times by simply using the macro name.
Sometimes there is confusion between macros and subroutines. Subroutines are common routines
that are written once by the programmer and then accessed by calling them. Subroutines are
usually used for longer and more complex routines where the call/return overhead can be tolerated.
Macros are commonly used for simpler routines or where the speed of the inline code is required.
Macro is defined as
for example to switch between the register banks, it is common to use a macro. Both programs in
the columns of the table are same.
Macros can be used with parameters, the assembler replaces the parameters with the arguments
when macro is used.
mymov macro source, destination org 0
mov destination, source mov A, #5
endm mov r1, #30h
again : mov @r1, A
goto macro label1 inc r1
sjmp label1 sjmp again
endm end
org 0
mymov #5,A
mymov #30h,r1
again: mymov A, @r1
inc r1
goto again
end
a) [8pts] Find the values of the registers after the execution of this program.
aoi22 macro a1,a2,b1,b2,z Answer :
mov A,a1
anl A,a2 R1 =
mov z,A
mov A,b1 R2 =
anl A,b2
orl A,z R3 =
cpl A
mov z,A R4 =
endm
R5 =
org 0
mov r1, #05h
mov r2, #0Ah
mov r3, #50h
mov r4, #0A0h
aoi22 r1,r2,r3,r4,r5
nop
aoi22 r1,r1,r4,r4,r3
nop
aoi22 r1,r1,r4,r4,r4
sjmp $
end
b) [9 pts] Write jg, jl, and je (use subb instruction for these macros, use registers A and B as
temporary if needed) and exchange macro (use registers A and B as temporary registers)
according to the descriptions
SUBB The subtract with borrow instruction subtracts the byte variable and the contents of the carry
from the accumulator, placing the result in the accumulator. The carry flag serves as a "Borrow
Required" flag during the subtraction; when a greater value is subtracted from a lesser value (eg, 1 - 6),
this requires a borrow, so the carry flag is set. On all other conditions, the carry flag is cleared.
SUBB A, R0 ;register, A = A - R0 - C
SUBB A, #23h
SUBB A, @R1
SUBB A, P0
endm
jl macro a1,a2,label2 if a1 is less than a2 (a1 < a2) then jump to
label2
endm
je macro a1,a2,label3 if a1 is equal to a2 then jump to label3
endm
exchange macro a1,a2 Change the values of the parameters
a1 -> temp
a2 -> a1
temp -> a2
We do not have
mov r1,r2 or mov @r1,@r2
instructions so
endm Use two temporary registers (A, B)
when you reach the end of the list it means the that the largest number is at the end.
If you loop the list will be sorted.
end