EEM336 MT1
Warnings
Example Questions
1
Exam Content
• As you can understand, the main focus of the
exam is assembly programming.
• The exam is composed of three sections
– (%20-%35) Short questions (5 points each)
– (%20-%35) Hand execution of programs. What are
the register values, ALU status codes after the
execution of the given program?
– (%15-%20) How many clock cycles does the given
program take?
– (%30-%40) Write a program. (mostly about lists.
shifting, counting, swapping, etc)
2
EEM336 MT1 QUESTIONS
Short Questions
• Q1: How is the performance of RISC processors are
improved?
– Answer: Intructions are reduced to execute each instruction
in 1 clock cycle.
• Q2: What is the size of SR register? ___ bytes
• Q3: Which bit in SR register that allows the MSP430
operate in low power modes?
• Q4: Is preincrement addressing mode available in
MSP430 microprocessor family?
• Q5: Which of the following instructions change the C
flag in SR ? ADD, BIC, XOR, JMP, BIS, AND
3
EEM336 MT1 QUESTIONS
Answer the following questions
• Q1: How many addressing modes are available in MSP430?
• Q2: How many clock cycles do the following instructions take?
MOV.W R12, R13 ___clock cycles
MOV.B @R12, 0(R13) ___ clock cycles
ADD.W R12, 8(R14) ___ clock cycles
ADD.W &ADDR, 0(R10) ___ clock cycles.
• Q3: Which addressing modes can be used in source addressing?
• Q4: Which symbol is used in absolute addressing mode?
• Q5: Which common symbol used in indirect autoincrement and indirect
mode?
• Q6: Which addressing modes are used in «mov.w @PC+,R6» instruction?
• Q7: What are R12, R13, R14 and R15 registers used for according to calling
conventions?
• Q8: When any subroutine is called, what is the first value at the top of the
stack inside the subroutine?
• Q9: What is the last instruction to be executed in a subroutine?
4
EEM336 MT1 QUESTIONS
Finding Machine Codes
• Find the machine codes for the following
instructions:
mov.w r11,2(r12)
xor.b @r9,8(r11)
bis.w @r9+,r12
and #0x1234,r14
mov r11,r12
rrc.w r12
5
EEM336 MT1 QUESTIONS
Short Questions
• Q1: mov.w @R5, 8(R4) exhibits
which MSP430 addressing modes?
– The MSP430 “mov” instruction supports a total of
how many destination addressing modes (only
consider the 4 fundamental addressing modes)
• Q2: If R5 contained the number 0x1234,
“mov @R5,R6” means what?
• Q3: How can you calculate the 2s complement
operation using XOR and ADD operations?
6
EEM336 MT1 QUESTIONS
Correction (Short Questions)
• Find the problems in these instructions,
understand what the intention is for writing
them in that form and try to correct them
mov r9,@r8
add.w #0x123456,r11
xor.w @r11+,@r12+
sub.w 0(r9),-1(r11)
push.w r9,@SP
7
EEM336 MT1 QUESTIONS
Reverse assembly the following
0x47C9 0x0008
0x5429
0x8E3A
0xE05F 0x1234
8
EEM336 MT1 QUESTIONS
Programs
• What is the final value of R10 in the following program?
.data ; data segment
var1 .word 0x5678 ; variable to be processes
.text ; Assemble into program memory.
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
begin mov.w &var1,r12 ; get the content of var to r12
mov.w #10,r11 ; loop counter
mov.w #0,r10 ; counter for number of 1s
loop1 bic #1,SR ; clear carry bit in SR
rrc.w r12 ; move 1 bit to the right Carry bit
jnc skip ; if the bit in C is zero, skip
inc r10 ; increment counter (we have 1 in C)
skip sub #1,r11 ; decrement loop counter
jnz loop1 ; if the loop counter is not zero, go
9
Programs
• What is the final value of R10 in the following program?
.data ; data segment
var1 .word 0xa228 ; variable to be processed
.text ; Assemble into program memory.
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
begin mov.w &var1,r12 ; get the content of var to r12
mov.w #8,r11 ; loop counter
mov.w #0,r10 ; counter
loop1 rrc.w r12
jnc skip
rrc.w r12
jc skip
inc r10 ; increment counter (we have 1 in C)
skip sub #1,r11 ; decrement loop counter
jnz loop1 ; if the loop counter is not zero, go
10
Programs
• Q1: Write a MSP430 assembly program that calculates the sum
of 8 x 16 bit numbers (i.e. words) in an array called buffer .
Create buffer in memory space and initialize with numbers
“9712,2454,1275,3312,4243,2395,4387,12236”.
• Q2: Write a MSP430 assembly program that calculates the
average of 8 x 16 bit numbers (i.e. words) in an array called
buffer . Define buffer in memory space and initialize with
numbers “9712, 2454, 1275, 3312, 4243, 2395, 4387, 12236”.
(Hint: shift 3 times to the right, divides the number by 8)
• Q3: Write a MSP430 assembly program that finds the number of
elements that are greater than 10000 in an array, called buffer.
Create buffer in memory space and initialize with numbers
“9712,2454,1275,3312,4243,2395,4387,12236,9454,32221”. The
result will go in R9. (Hint use CMP instruction)
11
EEM336 MT1 QUESTIONS
Short Questions
• Q1: Write a program to set bit 5 and clear the
3rd bit of R14
• Q2: How many read cycles needed to execute
– sub.w &0x0200, R7
– Machine code: 0x8217 0x0200
• Q3: How can you clear carry using bic
instruction?
• Q4: What are assembly directives are used for?
• Q5: The instruction “mov #45, &0x5678”
requires how many 16-bit operands?
12
EEM336 MT1 QUESTIONS
Short Questions
• Q6: Explain the concept of «sections» in
assembly language. What are «.text»,
«.data» and «.bss» sections used for?
• Q7: What is the purpose of linking?
13
EEM336 MT1 QUESTIONS
Question
• Fill out the contents of the MSP430 registers for the given code segment.
Your answers should reflect the content after each instruction has executed.
If the contents are unknown, write a question mark (?) in the blank. All
numbers should be given in hex! (note: org 0x200 directive means that the
assembly starts after memory address 0x0200)
org 0x0200
var1 .word 0x0 ; 2 bytes are reserved
var2 .word 0x0 ; 2 bytes are reserved
.text
main mov.w #0x1234, R4 PC = _______
mov.w R4, var1 M(var1) = _______
mov.w #var2, R6 R6 = _______
mov.w #0x1230, R6 R6 = _____
mov.w #0x1235, R7 R7 = _______
add.w R6, R7 R7 = _______
sub.w R6, R7 R7 = _______
bis.w #00001111b,R4 R4 = _______
xor.w R7, R7 R7 = _______
and.w R4, R4 R4 = _______
14
EEM336 MT1 QUESTIONS
Subroutines
• Write the following subroutines
– Q1: You are supposed to write a subroutine that takes a list
(16 bits) address in register R12 and length of the list in R11,
and returns the number of even values in R10.
– Q2: You are supposed to write a subroutine that takes two list
addresses in registers R11/R12 and length of the lists in R13,
and returns 1 in R14 if two lists are identical.
– Q3: You are supposed to write a subroutine that takes a list
(16 bit) address in register R12 and length of the list in R11,
and returns the sum of all list items in R10.
– Q4: You are supposed to write a subroutine that takes a list
(16 bits) address in register R12 and length of the list in R11,
and shifts all elements two bits to the right (i.e. Division by 4).
15
EEM336 MT1 QUESTIONS
Subroutine Examples
• How many cycles does it take to execute the
add2 subroutine?
main push #numk ; push the address of k
push #numr ; push the address of r
push #numres ; push the address of res
call #add2 ; Jump to Subroutine
add #6,SP ; restore stack (6 bytes)
jmp $
nop
add2 push r12
push r13
push r14
mov sp,r13 ; r13 is the frame pointer
mov 6(r13),r12 ; 6(r13) ptr (i.e. R12)
mov @r12,r14 ; *ptr r14
mov
add
mov
8(r13),r12 ; 8(r13) ptr (i.e. R12)
@r12,r14 ; r14 + *ptr r14
10(r13),r12 ; 10(r13) res (i.e. R12)
?
mov r14,0(r12) ; r14 *res
pop r14
pop r13
pop r12
ret
16
EEM336 MT1 QUESTIONS
Subroutine Examples
• How many cycles does it take to execute the
add3 subroutine?
main push #num1 ; push the address of num1
push #num2 ; Push the address of num2
call #add3 ; Jump to Subroutine
; R15 has the result
add #4,SP ; restore stack (4 bytes)
jmp $
nop
add3 push r12
push r13
mov sp,r13
mov 6(r13),r12 ; 6(r13) ptr (i.e. R12)
mov @r12,r15 ; *ptr r15
mov
add
8(r13),r12
@r12,r15
;
;
8(r13) ptr (i.e. R12)
r15 + *ptr r15
?
pop r13
pop r12
ret
17
EEM336 MT1 QUESTIONS