0

I can print character in label that in section .data But I can't print character use stack address

section .data
    break   db  "a"

section .text

global _start
_start:
    mov rax, qword 'a'
    push rax
    ; push 'a' to stack

    mov rax,4
    mov rbx,1

    ; get stack top pointer and mov to rcx register
    mov rcx,rsp
    ; If replace rsp with label <break> that can print newlines character
    ; mov rcx,break

    mov rdx,1
    int 80h

    pop rax

    call quit

quit:
    mov     rbx, 0      
    mov     rax, 1      
    int     80h
    ret

console>

not print anything

If replace rsp with label that can print newlines

; mov rcx, rsp 
mov rcx, break
console>a#

print one character

Makefile

.PHONY: test
test:
    nasm -f elf64 test.asm
    ld -s -o test test.o
    ./test

.PHONY: test_debug
test_debug:
    nasm -f elf64 -F dwarf -g test.asm
    ld -g -o test test.o
    gdb test
Kite
  • 21
  • 2
  • 1
    You shouldn't mix `int 80h` and 64-bit code. Refer to https://stackoverflow.com/questions/22503944/using-interrupt-0x80-on-64-bit-linux or https://stackoverflow.com/questions/46087730/what-happens-if-you-use-the-32-bit-int-0x80-linux-abi-in-64-bit-code – ecm Dec 04 '22 at 13:40
  • @ecm thank you so much for helping me solve a problem that has been puzzling me for a long time – Kite Dec 04 '22 at 13:51

0 Answers0