Homework #3
Assembly (Ch. 3), Assembler (Ch. 4), Stacks (Ch. 5)
In order to automate the grading process, please follow the exact instruction when answer
the questions and don’t use extra or unnecessary words.
1. (1 point) How does the circuit in a processor detect an OVERFLOW condition as defined
by 2’s complement addition? V flag
2. (3 points) A digital output port (8 bits) of an MSP430 processor is assigned to memory
location 0x0021. This output port controls 8 LEDs that are connected to Pins 0-7. Three
MSP430 assembly instructions can be used to turn ON and OFF and TOGGLE these LEDs.
For example, to control the LED connected to Pin 0, we can use
bic.b
bis.b
xor.b
#0x01, &0x0021
#0x01, &0x0021
#0x01, &0x0021
; turn off the LED
; turn on the LED
; toggle the LED
a. What assembly instruction turns on LEDs connected to Pins 3 and 4 at the same time?
bis.b #0x18, &0x0021
b. What assembly instruction turns off all 8 LEDs at the same time?
bic.b #0xFF, &0x0021
c. What assembly instruction toggles LEDs connected to Pins 1 and 7?
xor.b #0x82, &0x0021
3.
(6 points) For the following assembly code, give contents of R4 after each line is executed.
1.0x8000:
MOV.W
2.0x8004:
MOV.W
3.0x8008:
MOV.W
4.0x800c:
MOV.W
5.0x800e:
MOV.W
6.0x8010:
MOV.W
...
0x9000: FOOEY: .word
...
0xA000: FOOBAR: .word
#FOOEY,R4
&FOOEY,R4
FOOEY,R4
@R4,R4
@R4,R4
@R4+,R4
Answer
Answer
Answer
Answer
Answer
Answer
1:
2:
3:
4:
5:
6:
0x9000
0xA000
0xA000
0x9000
0xA000
0x9000
0xA000
0x9000
// Note: FOOEY = 0x9000
4. (3 points) The following operations are performed on a stack:
PUSH A, PUSH B, POP, PUSH C,
PUSH D, POP, PUSH E, PUSH F, POP,
POP, POP, PUSH F
a. What does the stack contain after the last PUSH F? A F
b. At which point does the stack contain the most elements? First PUSH F
c. Without removing any elements left on the stack from the previous operations, what does
the stack contain after the following additional operations? A F M
PUSH G, PUSH H, PUSH I, PUSH J,
POP, PUSH K, POP, POP, POP,
PUSH L, POP, POP, PUSH M
5. (10 points) How many cycles are used by each of the following instructions:
BYU, ECEn/CS 124
Homework #3
Page 1/2
a.
b.
c.
d.
e.
f.
g.
h.
i.
j.
mov.w r5,r6
mov.b r5,r6
add.b @r5,r6
add.b 10(r5),r6
sub.w 10(r5),20(r6)
mov.w #1,r5
mov.w #100,r5
jmp label
jne label
xor.w r5, label
1
1
2
3
6
1
2
2
2
4
6. (7 points) Create the symbol table entries (in correct order) generated by the assembler for
the following code. The code is loaded into memory starting at location 0x8382. Answer
your questions in hexadecimal number with “0x” (e.g., 0x8382).
SEED
.set
21845
; 65536/3
; UNSIGNED MULTIPLY: r4 x r5 -> r6|r7
;
MPYU: mov.w mySeed,r7
; LSB -> mySeed
clr.w r6
; 0 -> MSBs RESULT
2
1
; UNSIGNED MULTIPLY AND ACCUMULATE:
; (r4 x r5) + r6|r7 -> r6|r7
;
MACU: push r8
clr.w r8
; MSBs MULTIPLIER
1
1
L$01: bit.w #1,r4
jz
L$02
add.w r5,r7
addc.w r8,r6
; TEST BIT 5-4
; IF 0: DO NOTHING
; IF 1: ADD RESULT
1
1
1
1
L$02: rla.w
rlc.w
rrc.w
jnz
r5
r8
r4
L$01
; MULTIPLIER x 2
;
; NEXT BIT TO TEST
; IF C: FINISHED
1
1
1
1
L$03: pop
Ret
r8
mySeed:
.word SEED
1
1
Symbol
BYU, ECEn/CS 124
Question 1
SEED
Question 2
Question 3
Question 4
Question 5
Question 6
Question 7
MPYU
MACU
L$01
L$02
L$03
mySeed
Value
21845=
0x5555
0x8383
0x8388
0x838C
0x8394
0x839C
0x83A0
Homework #3
Page 2/2