Answer to Question #257354 in Assembler for joe

Question #257354

1.Write a program with three functions A(), B() and C(). B() is written in asssembly lang.

2. A() should call B() passing a 64-bit integer as an argument.

3. B() should be written in asm and interpret that as a 8-byte ASCII string and print individual characters on screen. You need to call the write() system call from assembly language using the syscall instruction, passing appropriate arguments.

4. Modify the stack in the function B() in such a way that when B() executes the ret instruction, it jumps to a third function C(). C() must also be written in C. This MUST happen without an explicit call to function C(). A mere ret from B, should pass the control to function C() instead of A(). Finally, the function C() needs to terminate the program by using the exit() system call.


1
Expert's answer
2021-11-04T16:27:04-0400
; qu.asm
; Assemble:    nasm -f elf64 -l qu.lst  qu.asm
; Link:        gcc -o qu  qu.o
; Run:        ./qu

   SECTION .data
strc:    db 10,13,"func c()",10,13,0
str:    dd 0
    
   SECTION .text           ; Code section.
   global main    
main:              
    call a
 
;***************************
 a:
;***************************
     mov rax,0x3031323334353637    ;64 bits integer
       mov rbx, c  
     push rbx
    call b
;***************************
  b:
;***************************
    mov [str], rax
    
; sys_write
    mov eax,4
    mov ebx,1
    mov ecx, str
    mov edx,8
    int 80h
    
    pop rax
    ret
;***************************
  c:
;***************************
; sys_write:  "func c()"
    mov eax,4
    mov ebx,1
    mov ecx, strc
    mov edx,13
    int 80h
 
 ; sys_exit    
    mov rax,1
    mov rbx,0
    int 80h

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