Answer to Question #143584 in Assembler for Promise Omiponle

Question #143584
Write assembly language code that uses a stack frame to implement the following high-level language function and its call. Do not optimize stack access in the function, (i.e.,
write all intermediate results to variables on the stack frame as indicated in the high-level language code).

/* Global variables */
word MemoryWord,
Result;
/* Function */
word IncMemWord (word *Pointer) {
word MemWord;
MemWord = *Pointer;
MemWord = MemWord + 1;
*Pointer = MemWord;
return MemWord;
}
/* Call */
Result = IncMemWord (&MemoryWord);
1
Expert's answer
2020-11-20T10:11:01-0500

.data

MemoryWord WORD 12

Result             WORD  ?

.code

main PROC

 

  mov edi, OFFSET MemoryWord   ; *Pointer

  push ebp  ; save the value of ebp in stack

  mov ebp, esp    ; set stack frame

      ; ebp now points to the top of the stack

                      

  push edi    ; push *Pointer

 

  call IncMemWord

  mov Result, ax   ; gets MemWord in ax

 

  add esp, 4 ; Restore stack pointer

  pop ebp   ; Restore ebp

 

 

IncMemWord PROC

  xor eax, eax

  mov esi, [ebp-4 ; *Pointer

  mov ax, [esi]  ; MemWord = *Pointer

 

 inc ax  ; MemWord = MemWord + 1

 mov [ebp-4], ax  ; *Pointer = MemWord

 ret    ; return MemWord in ax


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS