Question

Implement the following expression in assembly language:                                  &nb

  1. Implement the following expression in assembly language:

                                                BX = –val2 + 7 - (- val3 + val1) * 2

  • Assume that val1, val2, and val3 are 8-bit integer variables
  • Initialize val1 with 12, val2 with 9, and val3 with 2
  • You are only allowed to use 16-bit registers to hold intermediate results, whenever needed.
  • Use ONLY mov, add, sub, movzx, movzx, or neg instructions whenever needed.
  • Use the debugger to verify your answer.

Please answer using this format for code:

.386

.model flat, stdcall

.stack 4096

ExitProcess PROTO, dwExitCode:DWORD

.data

...(please initialize the variables)...

.code

...(insert code here)...

INVOKE ExitProcess,0

main ENDP

END main

Homework Answers

Answer #1
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
.data
val1 sbyte 0        ;intialize val1
val2 sbyte 0        ;intialize val2
val3 sbyte 0        ;intialize val3
result sword 0      ;intialize result
.code
main proc
mov val1,12         ;val1 = 12
mov val2,9          ;val2 = 9
mov val3,2          ;val3 = 2

mov ax,0
mov bx,0
mov cx,0
mov dx,0


movzx dx,val2       ;dx = val2
neg dx              ;dx = -val2
add dx,7            ;dx = -val2 + 7

movzx ax,val3       ;ax = val3
neg ax              ;ax = -val3 
movzx cx,val1       ;cx = val1
add ax,cx           ;ax = -val3 + val1
add dx,ax           ;dx = -val2 + 7 -val3 + val1

mov ax,dx           ;ax = dx
mul 2               ;ax = -val2 + 7 -val3 + val1 * 2
mov bx,ax           ;bx = result, = -val2 + 7 -val3 + val1 
invoke ExitProcess,0
    main endp
end main
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write an assembly program to compute the following expressions Create a list named ‘z’ of size...
Write an assembly program to compute the following expressions Create a list named ‘z’ of size 3 using DUP operator. Leave the list ‘z’ uninitialized. You can denote the items in the list as [z0, z1, z2]. z0 =x+13 z1 = y-x z2= r+z1-13 Where x, y, r are 16-bit integer memory variables. x = 7, y = 20, r = 4 Use the debugger to verify your answer. Please answer using this format for code: .386 .model flat, stdcall...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a...
Please complete in MASM (x86 assembly language). Use the code below to get started. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD .data    ; define your variables here .code main PROC    ; write your assembly code here    INVOKE ExitProcess,0 main...
PLEASE COMMENT CODE AND TEST THAT IT WORKS: Write a assembly program to find the largest...
PLEASE COMMENT CODE AND TEST THAT IT WORKS: Write a assembly program to find the largest item in an array and store it in a AX. Hint: Use both Jump and loop instruction to write the program. logic: Assume that the first item of the array is the minimum and store it in AX Write a loop. Inside the loop, compare the each array item with the AX If the array item is less than the AX, update AX with...
6. (True/False): The RET instruction pops the top of the stack into the instruction pointer. 8....
6. (True/False): The RET instruction pops the top of the stack into the instruction pointer. 8. (True/False): In protected mode, each procedure call uses a minimum of 4 bytes of stack space. 1. Which instruction pushes all of the 32-bit general-purpose registers on the stack? 20. What values will be written to the array when the following code executes? .data array DWORD 4 DUP(0) .code main PROC mov eax,10 mov esi,0 call proc_1 add esi,4 add eax,10 mov array[esi],eax INVOKE...
Implement the following C++ expression val1 = (val2 * val3) / (val4 − 3) in assembly...
Implement the following C++ expression val1 = (val2 * val3) / (val4 − 3) in assembly language using: • 8-bit unsigned operands • 16- bit unsigned operands • 32-bit unsigned operands a- Use the MASM assembler with .Data to initialize your variables, write your code in the .code segment. Add comments explaining your code b- Modify the code to prompt the user to enter the information -use 32-bit unsigned operands only-, and show the output on the console, and dump...
A) Is the code below secure? Explain your rationale. ExitProcess PROTO .data firstval qword 20002000h secondval...
A) Is the code below secure? Explain your rationale. ExitProcess PROTO .data firstval qword 20002000h secondval qword 11111111h thirdval qword 22222222h sum qword 0 .code main proc      mov rax,firstval                         add rax,secondval             add    rax,thirdval      mov    sum,rax      mov    ecx,0      invoke ExitProcess main endp end main b) Transmitted messages often include a parity bit, whose value is combined with a data byte to produce an even number of 1 bits. Suppose a message byte in the AL...
13. (True/False): The register list in the USES directive must use commas to separate the register...
13. (True/False): The register list in the USES directive must use commas to separate the register names. 11. (True/False): The USES operator lets you name all registers that are modified within a procedure. 2. Which instruction pushes the 32-bit EFLAGS register on the stack? 18. Which statement is true about what will happen when the example code runs? 1: main PROC 2: mov eax,40 3: push offset Here 4: jmp Ex4Sub 5: Here: 6: mov eax,30 7: INVOKE ExitProcess,0 8:...
In MPLAB XIDE create a program using assembly to produce three different LED combinations using 4...
In MPLAB XIDE create a program using assembly to produce three different LED combinations using 4 LED lights and 4 switches that correspond to each LED. There will be 4 inputs and 4 outputs. The program includes three levels (the three LED combinations). Each level will be a random combination (i.e. red, blue, green, orange). The player will then repeat the combinations as accurately as possible. If the player repeats the led sequence correctly, the code will branch to the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT