我正在尝试从标准输入读取字符串并使用 x86、NASM 和系统调用将其打印出来。读入一个字节将是一个函数,而写出一个字节将是一个函数。我正在从标准输入读取字符串并将每个字符放入一个数组中。这是我最初的想法:
;read_writer.asm
section .data
arr times 100 db 0 ; array of 100 elements initialzed to 0
ptr dd 0
section .text
global _start
_start:
push ebp ; setup stack
mov ebp, esp ; setup stack
push, 0x10 ; allocate space for potential local variables
call readin: ;call read in func
push eax ;return char from readin will be in eax, push it for writeout
call writeout:
leave
mov eax, 1 ;exit
mov ebx, 0
int 0x80
readin:
push ebp
mov ebp, esp ; setup stack
mov eax, 3 ;read
mov ebx, 1 ;stdin
; i feel like i am missing code here bit not sure what
leave ;reset stack
ret ;return eax
writeout:
push ebp
mov ebp, esp ; setup stack
push eax ;push eax since it was pushed earlier
mov eax, 4 ;write
mov ebx, 1 ;stdout
; i feel like i am missing code here bit not sure what
leave ;reset stack
ret ;return eax
样本输入:
Hello World
样本输出:
Hello World
这些函数应该与 cdecl 一起使用,我认为我做得不对。我也意识到我没有将字符放入 arr。