Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using assembly language , implement printf. But not the whole thing. You are onl

ID: 3915333 • Letter: U

Question

Using assembly language, implement printf. But not the whole thing. You are only responsible for:
• %s prints a string
• %c prints a characters
• %% prints a literally percent sign (%)
And there’s a catch: You’re ONLY allowed to use system calls to print data. No print_char, no
print_string, etc.


Example Code:

segment .data
str1 db “Hello world”,10,0
str2 db “str3 is ‘%s’, isn’t that cool?”,10,0
str3 db “woot woot”,0
str4 db “%c is a char, but so is %%, %s again!”,10,0
segment .text
global asm_main
asm_main:
push str1
call printf
add esp, 4
push str3
push str2
call printf
add esp, 8
push str3
push ‘A’
push str4
call printf
add esp, 8

Explanation / Answer

.LC0:

.string "%s"

.LC1:

.string "%%"

main:

push rbp

mov rbp, rsp

sub rsp, 16

mov DWORD PTR [rbp-16], 1280066888

mov WORD PTR [rbp-12], 79

mov BYTE PTR [rbp-1], 103

lea rax, [rbp-16]

mov rsi, rax

mov edi, OFFSET FLAT:.LC0

mov eax, 0

call printf

movsx eax, BYTE PTR [rbp-1]

mov edi, eax

call putchar

mov edi, OFFSET FLAT:.LC1

mov eax, 0

call printf

mov eax, 0

leave

ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote