CSCI 150编程代写、代做c++,python
CSCI 150 -- Lab 3
Programming in Assembly Language
Due:________________________
Feel free to discuss and help each other out, but does not imply that you can give away
your code or your answers! Make sure to read all instructions before attempting this lab.
Refer to the MSVS 2017/2019 document on Canvas and obtain helps from your
instructor as necessary. You cannot work with a lab partner for this assignment.
You must use an appropriate Provided template from Canvas or my website
(zeus.mtsac.edu/~tvo) and output "Author: Your Name(s)" for all new
programs. If you are modifying an existing program, use "Modified by: Your
Name(s)".
Exercise 1: Using the AddSub program from the book as a reference, write an assembly
program to perform the following operations using only 16-bit registers: AX = 20 - (15 +
30). You must perform 15 + 30 first and then perform the subtraction operation. Use
additional registers as needed. Insert a call DumpRegs statement after each operation
and confirm that AX is holding the correct result. Add a comment after each instruction
to describe it. For example:
mov bx, 1 ; assign 1 to bx so bx = 1
add bx, 2 ; add 2 to bx so bx = 3
In addition, display the message "Author: Your Name." at the beginning of your program
by defining a null-terminated string and then add a call WriteString instruction.
Once your program is working correctly, modify it to add the following calculation: BX
= a - (b + d), but do keep the Code from previous step. Once again, you must perform
addition operation first and then perform the subtraction operation. Define variables a, b,
and d as 16-bits signed integers with values 20, 15, and 30 respectively. Use DumRegs
to confirm that it calculates the result for BX correctly.
; instructions to calculate AX = 20 – (15 + 30), using constants
; instructions to calculate BX = a – (b + d), using variables
; AX and BX should have the same value
Exercise 2: Write an assembly program in 32-bit Protected mode that implements the
following arithmetic expressions using as few instructions and registers as possible
without simplifying the Expression manually (i.e., perform operations in correct order
according to normal precedence and use variables as applicable). Assume that r1 is a 32-
bit signed value and r2 is a 16-bit unsigned value. You can confirm that variables r1 and
r2 hold correct values by assign them to different registers and call DumpRegs.
r1 = -(v2 – (v3 + v1)) + 1
r2 = v4 + 10h
Use the following data definitions:
v1 SDWORD 10h
v2 SDWORD 30h
v3 SDWORD 20
r1 SDWORD ?
v4 WORD 0FFFFh
r2 WORD ?
In comments next to each instruction, write the current hexadecimal value of the affected
register or variable (for example: mov eax, 12 ; eax = 0Ch). Insert a call
DumpRegs Statement at the end of the program and you should examine various registers
to confirm that your Program is working properly. In addition, display the message
"Author: Your Name." at the beginning of your program by defining a null-terminated
string and then add a call WriteString instruction.
Lab question 1: How does MSVS know that you are working with an assembly program
instead another program such as C++?
Lab question 2: What do you have to modify in your program to compute EBX = a - (b
+ d)? Just answer the question without modifying your program.
Extra Credit (1.5 points): Add code to second exercise to display the decimal values in
r1 and r2 in correct format to the screen in for exercise 2.
r1: [whatever value for r1]
r2: [whatever value for r2]
Fill out and turn in the PA submission file for this assignment (save as PDF format).
请加QQ:99515681 或邮箱:99515681@qq.com WX:codehelp
|