我對 NASM 非常陌生,發現它非常混亂。我想知道是否可以尋求幫助來創建一個程式,該程式在單獨的行中顯示字串中的每個字符。我相信這必須在不修改字串的情況下完成。
*Example*
String: helloworld
Output:
h
e
l
l
o
w
o
r
l
d
我對匯編語言很迷茫,所以這就是我設法嘗試的全部:
section .data
msg: db 'Helloworld\n', 10
len: equ $-msg
section.text
global _start
_start:
mov edx, len
mov ecx, msg
mov ebx, 1
mov eax, 4
int 0x80
mov eax, 1
int 0x80
這會輸出 Helloworld\n 。任何幫助,將不勝感激!
uj5u.com熱心網友回復:
這會輸出 Helloworld\n 。
如果您希望 NASM 理解您的轉義換行符 '\n' (嵌入在字串中),那么您必須用反引號替換引號。
交換msg: db 'Helloworld\n', 10:
msg: db `Helloworld\n`
每行一個字符
您必須創建一個回圈,從字串中獲取單個字符并單獨輸出。最好將每個單個字符與換行代碼組合在一起,然后將這 2 個位元組寫在一起。
mov eax, 0x00000A00 ; Newline in second position
push eax ; Small buffer on the stack
mov esi, msg
jmp BeginLoop
ContLoop:
mov edx, 2 ; Writing character plus newline
mov ecx, esp
mov [ecx], al ; Character in first position
mov ebx, 1
mov eax, 4
int 0x80
BeginLoop:
movzx eax, byte [esi]
inc esi
cmp al, 10
jne ContLoop ; Go output if not at end of message
pop eax ; Remove the small buffer
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/532997.html
標籤:Intel Collective linux部件x86鼻涕虫
