In: Computer Science
in assemby, please share code and output - thanks
1. First clear all your general purpose registers by moving the value “0” into them. Initialize a variable for a BYTE, WORD, DWORD storage size each with any desired value in the data segment. Initialize another variable called Result with the size of a DWORD and make the value as an uninitialized value. In the code segment, create a label called L1 that moves the variables in the appropriate sized register and making sure NOT to overwrite them in the process. After, create another label L2 that adds all these values together and at the end of your program make sure your ECX register contains the final value. Call the DUMPREGS instruction to display your register values and move the final result into the Result variable.
2. Use the following code below as a template and follow the instructions written in the comments ;Assume I have the following data segment written: .data val1 BYTE 10h val2 WORD 8000h val3 DWORD 0FFFFh val4 WORD 7FFFh ;1. Write an instruction that increments val2. ;2. Write an instruction that subtracts val3 from EAX. ;3. Write instructions that subtract val4 from val2. .code ;Write your instructions here
Here is the solution to the above question. For your convienience I have attached the code.
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
INCLUDE Irvine32.inc
.data
MOV EAX, 0
MOV EBX, 0
MOV ECX, 0
MOV EDX, 0
val1 BYTE 10h
val2 WORD 8000h
val3 DWORD 0FFFFh
val4 DWORD 7FFFFh
result DWORD FFFFFh
.code
main PROC
MOV EAX, 10
L1:
INC val2 // Incrementing val2
SUB EAX,val3 //Subtracting val3 from EAX and storing it in EAX
MOV EBX,val4
SUB val2,EBX // No registers are over-written at the end of L1
MOV EDX,val2 // Subtracting val4 from val2 and the result is moved into EDX register
L2:
ADD EDX,EAX
ADD EDX,EBX // Adding all the values
MOV ECX,EDX // At the end of L2 the result is being moved to ECX register
call DumpRegs ;Check registers via output
MOV result,ECX // Moving the final result from ECX register to the result variable
invoke ExitProcess,0
main ENDP
end main
If you find this solution helpful please do UPVOTE this answer as your upvote motivates me to help students like you who are eager to learn.
HAPPY LEARNING!!!!!!!!!!!!