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