Write code using the Microsoft Assembly Language MASM. Your program must be prop
ID: 3595793 • Letter: W
Question
Write code using the Microsoft Assembly Language MASM. Your program must be properly Include comment lines at the end of each line. A. Integer Expression Calculation Write a program that calculate the following expression, using registers: A (A +B) - (C - D) Assign integer values to the EAX, EBX, ECX, EDX registers. Provide a screenshot or copy the values of the results and include with your program. B. Machine Language Listing Generate a listing of the above program and write a description of the machine code bytes generated for each instruction. You may have to guess at some meanings of the byte values.Explanation / Answer
1. Program to calculate the following Exapression
a=(a+b)-(c-d)
.data
a: .word 0x42
b: .word 0x43
c: .word 0x44
d: .word 0x45
.text
start: set a, %r1
ld [%r1], %r2 ! $a$ --> %r2
set b, %r1
ld [%r1], %r3 ! $b$ --> %r3
set c, %r1
ld [%r1], %r4 ! $c$ --> %r4
set d, %r1
ld [%r1], %r5 ! $d$ --> %r5
add %r2, %r3, %r2 ! $a+b$ --> %r2
sub %r4, %r5, %r3 ! $c-d$ --> %r3
sub %r2, %r3, %r2 ! $(a+b)-(c-d)$ --> %r2
set a, %r1
st %r2, [%r1] ! $(a+b)-(c-d)$ --> a
end: ta 0
2.description of the machine code bytes generated for each instructions.
Example]::
================
The MIPS architecture provides a specific example for a machine code whose instructions are always 32 bits long.
The general type of instruction is given by the op (operation) field, the highest 6 bits.
J-type (jump) and I-type (immediate) instructions are fully specified by op. R-type (register) instructions include an
additional field funct to determine the exact operation. The fields used in these types are:
6 5 5 5 5 6 bits
[ op | EAX | EBX | ECX |EDX| funct] R-type
[ op | EAX | EBX | address/immediate] I-type
[ op | target address ] J-type
EAX, EBX, ECX,and EDX indicate register operands; shamt gives a shift amount; and the address or immediate fields contain an operand
directly.
For example, adding the registers 1 and 2 and placing the result in register 6 is encoded:
[ op | EAX | EBX | ECX |EDX| funct]
0 1 2 6 0 32 decimal
000000 00001 00010 00110 00000 100000 binary
Load a value into register 8, taken from the memory cell 68 cells after the location listed in register 3:
[ op | EAX | EBX | address/immediate]
35 3 8 68 decimal
100011 00011 01000 00000 00001 000100 binary
Jumping to the address 1024:
[ op | target address ]
2 1024 decimal
000010 00000 00000 00000 10000 000000 binary
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.