Docsity

Preparation Exercise 7 Solutions - Microprocessors and Digital System | ECE 331, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
p. 1
ECE 331 Preparation Exercise 7 Solutions
Please refer to Module 5.1-5.3 course notes to answer the following questions.
1. Two programming elements that allow a sequential program to achieve non-sequential operation
(like conditional operation or looping) are Branching and Subroutine calls. What is the main
difference between a branch and a subroutine?
Subroutines are able to return to the point from which the subroutine was called, while
Branch will move to a new location in the code without knowledge of where it came from.
2. Briefly describe the difference between conditional and unconditional branches.
Unconditional branches will always occur while conditional branches will only occur (be
“taken”) if a specific condition is true. Conditions are determined by the state of status
flags after executing the previous instruction.
3. Identify the assembly instruction syntax best used for each of the following cases:
a) Branch always to an address held within a register
b) Branch always to a subroutine at an addressed held within a register
c) Branch always to an address determined by a label
d) Branch always to a subroutine at an addressed determined by a label
a) BX <Rm>
b) BLX <Rm>
c) B <label>
d) BL <label>
4. Identify the conditional assembly instruction mnemonic suffix for each of the following conditions:
a) if not equal
b) if signed result is less than
c) if positive
d) if lower or same
e) what is the difference between instructions B R0 and BAL R0?
a) BNE
b) BLT
c) BPL
d) BLS
e) they are functionally the same
5. Stack Basics
a) Briefly define the Stack of a microcontroller.
Stack is a section of RAM used for temporary storage that uses the Stack Pointer (SP)
CPU register to track the next open position (top of) the stack.
b) Does the stack pointer point to (contain the address of) 1) the last byte of data placed on
the stack and accessible by POP or 2) the next free memory block on stack to store data with
PUSH?
SP points to the last data placed on stack, so (1) above is correct. In order to PUSH new
values to stack, the SP must first be changed to SP-4 (moving it deeper into the stack)
pf3

Partial preview of the text

Download Preparation Exercise 7 Solutions - Microprocessors and Digital System | ECE 331 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

ECE 331 Preparation Exercise 7 Solutions

Please refer to Module 5.1-5.3 course notes to answer the following questions.

1. Two programming elements that allow a sequential program to achieve non-sequential operation

(like conditional operation or looping) are Branching and Subroutine calls. What is the main difference between a branch and a subroutine?

Subroutines are able to return to the point from which the subroutine was called, while

Branch will move to a new location in the code without knowledge of where it came from.

2. Briefly describe the difference between conditional and unconditional branches.

Unconditional branches will always occur while conditional branches will only occur (be

“taken”) if a specific condition is true. Conditions are determined by the state of status

flags after executing the previous instruction.

3. Identify the assembly instruction syntax best used for each of the following cases:

a) Branch always to an address held within a register b) Branch always to a subroutine at an addressed held within a register c) Branch always to an address determined by a label d) Branch always to a subroutine at an addressed determined by a label

a) BX

b) BLX

c) B

d) BL

4. Identify the conditional assembly instruction mnemonic suffix for each of the following conditions:

a) if not equal b) if signed result is less than c) if positive d) if lower or same

e) what is the difference between instructions B R0 and BAL R0?

a) BNE

b) BLT

c) BPL

d) BLS

e) they are functionally the same

5. Stack Basics

a) Briefly define the Stack of a microcontroller.

Stack is a section of RAM used for temporary storage that uses the Stack Pointer (SP)

CPU register to track the next open position (top of) the stack.

b) Does the stack pointer point to (contain the address of) 1) the last byte of data placed on the stack and accessible by POP or 2) the next free memory block on stack to store data with PUSH?

SP points to the last data placed on stack, so (1) above is correct. In order to PUSH new

values to stack, the SP must first be changed to SP-4 (moving it deeper into the stack)

6. Identify the assembly instruction that implements the following stack operations:

a) load a value from the top of the stack into a register b) place a register value onto the stack at the location indicated by the SP register

a) POP

b) PUSH

7. For the KL25Z, what is the possible memory address range for the stack?

RAM exist between 0x2000.0000 and 0x2000.2FFF, and the stack can be placed

anywhere in RAM.

8. Briefly define each of the following terms used to describe subroutine procedures.

a) An independent subroutine does not rely on another other program or

subroutine code since that code could be changed without the subroutine knowing it was

changed.

b) A transparent subroutine will return the CPU to the same state it was in when

the subroutine was called, which primarily involves restoring CPU registers to the value

they held prior to the subroutine call.

c) A relocatable subroutine does not rely on any data in specific memory locations

and the code of the subroutine can be moved to a new location (memory address)

without affecting the operation of the subroutine.

9. The section of assembly code below is from the Keil project “EX_BranchStack“ and was used in

an in-class active learning exercise. Create a flowchart for this code that maps its flow. The flowchart does not have to be “linear”; it can branch to non-linear actions.

Solution flowchart at the end of this document

10. The flowchart below includes two conditional tests

and a subroutine. Create a new flowchart that defines how the program that executes this flowchart would be implemented within “linear” code, i.e. all actions must flow in a line with unconditional branches added as needed to achieve proper operation. You may assume the subroutine function will appear after the main loop.

Solution flowchart at the end of this document