首页 » 汇编辅导 » Assembly辅导 | CIS 21JA – Assignment 7

Assembly辅导 | CIS 21JA – Assignment 7

这个Assignment是使用汇编操作寄存器数据
CIS 21JA – Assignment 7

Overview
Modify the code of lab 5 so that the program is divided into procedures. The code should still do the same work as lab 5: add 2 unsigned, 16-bit integers and print the sum as a numeric text string.

[This means:
– If you didn’t get full credit for lab 5, then you should read the feedback comments that are specific to your lab and fix the code, so that you don’t get the same point deduction again.
– If you got below 11pts for lab 5 (not counting late points), then the suggestion in your lab feedback to come see me to discuss questions on the lab is still an offer, and /or the solution to lab 5 is in the module 5 Questions forum]

Details
Take the code of lab 5 and divide it into the following 4 procedures and 1 macro.
1. A readInput procedure that uses registers to pass data.
The procedure prompts the user for one 16-bit positive integer and keeps prompting until there is a valid input.
The procedure:
a. has 2 input arguments: the address of the prompt string and the address of the error string (for “input out of range” error).
b. uses the addresses of the prompt string to prompt the user, checks for invalid input, and uses the address of the error string to print the error message as necessary.
c. keeps looping to do step b until there’s a valid input.
d. returns a valid user input.

2. An add2 procedure that uses the stack to pass data.
The procedure adds the 2 numbers, passes back the sum through an address, and returns a boolean to show whether the sum is valid.
The procedure:
a. has 3 input arguments: the 2 input numbers and the address of the sum.
b. does a 16-bit addition and checks for invalid sum by using 16 bit data only. Just as with lab 5, do not use 32 bits to check for invalid data.
c. passes back the sum though its address (which is on the run time stack)
d. returns a boolean (through the stack) to show valid or not valid sum.
The boolean is 1 of any 2 values to indicate valid / not valid. A common set of values to use is 0 and 1, but any 2 values would be okay as long as the calling procedure knows what they mean.

3. A convert procedure that uses the stack to pass data.
The procedure converts the sum to a numeric text string.
The procedure:
a. accepts 2 input arguments: the sum and the address of the array of characters (the numeric text string)
b. loops to convert the sum into characters that are put in the array
c. has no return value. (This is how arrays in high level language works: the function can modify the data in the array because arrays are passed by address or reference, so there’s no need to return the array)

4. A main procedure that coordinates the calling of the 3 previous procedures and prints the result.
The main procedure:
a. calls the readInput procedure twice, once for each user input
b. calls the add2 procedure and checks the boolean return value
c. if the sum is valid, calls the convert procedure and print the sum
d. if the sum is not valid, prints the error message
e. loops to ask the user to continue or end

5. A macro that accepts a string address and prints the string to screen.
a. Use your own choice of name for the macro
b. Use the macro whenever you need to print a text string. This means when you prompt the user, print an error message, and print the sum as a string.

How the main function would be in pseudocode:
do
num1 = readInput()
num2 = readInput()
if add2(num1, num2, address_of_sum) is valid
print sum
else
print error message
ask user to continue
while user wants to continue

Additional requirements
• Document your program (your name and a short description of the program at top, at minimum) to get full credit.
• Create 3 variables for the 2 user input and the sum. These should all be 16-bit variables.
Even though in assembly we try to use registers whenever possible, these variables represent data variables in a high level language code, and for this lab your assembly code is working with data of the high level language code.
• Make sure the procedures pass data either through the stack or through registers as described above.
1pt per procedure (3 pts total) is for using the required way to pass data.
• For the 2 procedures that pass data through the stack, the code should clear out the stack frame completely when the procedure call is done.
1 pt per procedure (2pts total) is for clearing out the stack correctly.
• Make sure add2, convert, and the macro save and restore registers that they use.
• Except for the main procedure, no other procedure should access variable names in .data directly. Only use data that are passed through the stack or register.

Testing
Test your result adequately: with valid and invalid input, with valid and invalid sum. Your program output should be the same as with lab 5.


程序辅导定制C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持 Alipay WeChatPay PayPal等支付方式

E-mail: vipdue@outlook.com  微信号:vipnxx


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank

发表评论

您的电子邮箱地址不会被公开。