我正在撰寫一個編譯器,試圖將我的編程語言從解釋轉換為編譯
這是我的腳本生成的代碼:
section .bss
digitSpace resb 100
digitSpacePos resb 8
string_at_index_0 resb 12
string_at_index_0_len resb 4
section .data
section .text
global _start
_start:
mov rax, "Hello world"
mov [string_at_index_0], rax
mov byte [string_at_index_0_len], 13
mov rax, 1
mov rdi, 1
mov rsi, string_at_index_0
mov rdx, string_at_index_0_len
syscall
mov rax, 60
mov rdi, 0
syscall
當我運行此代碼時,nasm -f elf64 -o test.o test.asm我收到此警告:
warning:character constant too long [-w other]
任何人都可以幫我解決這個問題,以及是否有人可以提出一種更好的方法來輸出一個 Hello 世界,這也很有幫助!
uj5u.com熱心網友回復:
mov rax, "Hello world"
RAX 是一個 64 位(8 位元組)暫存器,您嘗試將 11 個位元組放入其中。
這是一個簡單的hello world:
可以看出,您不想將訊息放入暫存器中,而是希望將指向訊息的指標放入 rsi。
section .data
msg: db "Hello World"
section .text
global _start
_start:
mov rax, 1 ; write function
mov rdi, 1 ; to stdout
mov rsi, msg ; pointer to message
mov rdx, 11 ; length of the message
syscall ; write
理想情況下,您的編譯器應該在部分中宣告字串文字,.data并在函式中使用它們時傳遞指向它們的指標。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/514444.html
