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.
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
Comments
Leave a comment