stdin から文字列を読み取り、x86、NASM、および Syscalls を使用して出力しようとしています。バイトの読み取りは関数になり、バイトの書き込みは関数になります。stdin から文字列を読み取り、各文字を配列に入れています。これが私の最初のアイデアです:
;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に入れていないことにも気付きました。