次のことを行うプログラムを実行しようとしています: ファイルの入力を受け取ります: 10 文字、すべて CAP、それらすべてをそれぞれアルファベットで 3 桁進め、Z ASCII コードを超えるものは 26 桁減算されます。Z->D、A->D、D->H など。
コード: 文字 + 3 if (コード > 26) コード: コード - 26
それが言うことを正確に行う私のreadByte関数:各行はよくコメントされています!
mov ecx, 0
mov edi, buffer ; buffer is memory address of 1st char of file
readByte:
mov al, [edi] ; move x's position content to al
add al, 3 ; add 3 to al
cmp al, MAXHEX ; compare with 'Z'
jg dec ; if al > 'Z', jump to dec
call putChar ; if al < 'Z', print char
jmp nextByte ; grab next character!
dec:
sub al, 26 ; decrement al by 26
call putChar ; print char
jmp nextByte ; grab next char
nextByte:
cmp ecx,[filesize] ; compare counter and filesize I had returned from readFile
jge terminar ; if it has read all chars, end program
inc ecx ; increment counter
inc edi ; advance to next file address position, so as to get next character
jmp readByte ; go read the byte again
これはエッセイのために私たちに渡された putChar マクロです。
; putChar - write a char to stdout (stdout)
; Argument(or whatever you call it in assembly)
; al: char to write
; Return: has none
putChar:
push ebx
push ecx
push edx
push eax ; al has the ascii code to write
mov ecx, esp ; esp points to top of stack
mov edx, 1 ; write a character
mov eax, SYS_WRITE ; 4
mov ebx, 1 ; channel of screen ecran - stdout
int LINUX_CALL
pop eax
pop edx
pop ecx
pop ebx
ret
基本的に、変更すれば、プログラムを完全に機能させることができます
add al, 3 ; add 3 to al
別の値に。何が悪いのかわかりません。この 1 つの単純なことに少なくとも 12 時間費やしました。