0

I am trying to gain a better understanding of the 'putchar' subroutine in assembly to make my own printf function. For this specific problem I want to print the first 2 bytes of the string "Hello world"

The code i am using is as followed:

.text
hello: .asciz "Hello, world!"

.global my_main


my_main:
        # IMPLEMENT ME
        # Prolougue
        pushq %rbp
        movq %rsp, %rbp

        # move the string to %rsi
        leaq hello(%rip), %rsi

        # print the first and second characters of the string in rsi 
        movb (%rsi), %dil
        call putchar
        
        movb 1(%rsi), %dil
        call putchar


        # Epilogue
        movq %rbp, %rsp
        popq %rbp
        ret

When I try to print the first and second character individually I get the result I want, but when I try to get both the first and second characters together it only prints the first.

This is the first time I asked a question on here so feel free to point out any improvements as long as you do it nicely (:

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Tonko
  • 1
  • 1

0 Answers0