0

我正在尝试做一个程序,它执行以下操作:它需要一个文件的输入: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

到不同的价值。我不知道出了什么问题。在这件简单的事情上花了至少十几个小时。

4

0 回答 0