Answer to Question #257358 in C for joe

Question #257358

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-10-27T18:51:34-0400
A():
        push    rbp
        mov     rbp, rsp
        mov     edi, 3
        call    B(int)
        nop
        pop     rbp
        ret
.LC0:
        .string "%d"
B(int):
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], edi
        mov     eax, DWORD PTR [rbp-4]
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC0
        mov     eax, 0
        call    printf
        nop
        leave
        ret
C():
        push    rbp
        mov     rbp, rsp
        nop
        pop     rbp
        ret

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