You’ll write your first complete assembly language program using what you’ve learned in class. You will use the following in your program:
You’ll write a program that interprets a series of operands and operations and stores the results - an assembly language calculator!
0x0200
.0x0201
.END_OP
- at which point, your program will cease execution.0x0200
.equ
where appropriate) must be used throughout (review the lessons if you are unclear on what this means).space
)Your program will implement the following operations:
ADD_OP
An addition operation is coded by the value 0x11
. It adds two numbers and stores the result. The calculator program 0x14 0x11 0x12
is equivalent to 0x14 + 0x12
. It would store the result 0x26
.
SUB_OP
An subtraction operation is coded by the value 0x22
. It subtracts two numbers and stores the result. The calculator program 0x21 0x22 0x01
is equivalent to 0x21 - 0x1
. It would store the result 0x20
.
MUL_OP
An multiplication operation is coded by the value 0x33
. It multiplies two numbers and stores the result. The calculator program 0x02 0x33 0x04
is equivalent to 0x02 * 0x04
. It would store the result 0x08
.
The MSP430G2553 that you’re using does not have a hardware multiplier, so think how multiplication works and implement an algorithm. It doesn’t has to be the fastest algorithm, it just has to work. Also, we are only working with integer numbers.
CLR_OP
A clear operation, represented by the value 0x44
, clears the result by storing 0x00
to memory. It then uses the second operand as the initial value for the next operation. The calculator program 0x21 0x22 0x01 0x44 0x14 0x11 0x12
is equivalent to 0x21 - 0x1 CLR 0x14 + 0x12
. It would store 0x20 0x00 0x26
.
END_OP
The end operation terminates execution of the calculator. It is coded by the value 0x55
.
Example calculator program: 0x14 0x11 0x32 0x22 0x08 0x44 0x04 0x11 0x08 0x55
It’s equivalent to: 0x14 + 0x32 - 0x08 CLR 0x04 + 0x08 0x55
. The result should be, stored at 0x0200
: 0x46 0x3e 0x00 0x0c
If your program gets an byte that is not in the above instruction set, it will reset. Any values already stored in the 0x0200
output location will be retained, but any operands pushed into a register will be cleared (or just forgotten) and your program will start back through its flowchart for reading inputs.
Although some of these operations are really simple, you need to start thinking about how to break up a program into logical chunks.
Proper documentation is important. If another programmer needs to maintain your code (or in our case, grade your code) and they cannot easily follow it, because you failed to properly document it, then that is a failure.
Your program is going to be reading a series of operands and operations from memory. Use the .byte
directive to store them!
.text
myProgram: .byte 0x13,0x22,0x14,0x11,0x37
Your program is going to be storing results to memory. Use the .space
directive to store space for them!
.data
myResults: .space 20 ; reserving 20 bytes of space
Hex values code for operations. I better not see any magic numbers!
ADD_OP: .equ 0x11
SUB_OP: .equ 0x22
This is due at the beginning of the lab class
You will hand in a flow diagram of how your program will work (use PowerPoint). Your flow chart must start from when the program starts running until your program receives an END_OP
Answer the following questions:
0x55
(END_OP) command?Here are the test cases you must demonstrate to your instructor before the end of the class:
0x11, 0x11, 0x11, 0x11, 0x11, 0x44, 0x22, 0x22, 0x22, 0x11, 0xCC, 0x55
0x22, 0x33, 0x00, 0x00, 0xCC
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0xDD, 0x44, 0x08, 0x22, 0x09, 0x44, 0xFF, 0x22, 0xFD, 0x55
0x22, 0x33, 0x44, 0xFF, 0x00, 0x00, 0x00, 0x02
0x22, 0x11, 0x22, 0x22, 0x33, 0x33, 0x08, 0x44, 0x08, 0x22, 0x09, 0x44, 0xff, 0x11, 0xff, 0x44, 0xcc, 0x33, 0x02, 0x33, 0x00, 0x44, 0x33, 0x33, 0x08, 0x55
0x44, 0x11, 0x88, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff
When you demo, due to time limitations, you only get one chance to demo each of the four programs for full credit, so make sure it works (repeatedly) before you show the instructor. Any follow-on demos will result in a 10% penalty each time. Also, demos will only be done in class. If you demo after class, then you are subjected to a 25% penalty.
lab 1 init project
or lab 1 final working code check by instructor