1

我两次尝试从输入中读取字符,第一次“调用 getUserAction”工作正常,但主要问题是,系统没有调用第二个读取函数,它只是退出。这是我的代码的一小部分

SECTION .bss
        buffer resb 1
SECTION .text
    global _start
    _start:
    ...some unuseful and commented code
    call getUserAction ;reading 1 byte from console, works fine
    ...
    jmp count
    call exit
    count:
           ...
           call getUserAction; don't work, just exits from program without err
           ...commented code to debug
           call exit

    getUserAction: ;proc to read from console 1 byte
             mov eax, 3
             mov ebx, 0
             mov ecx, buffer
             mov edx, 1
             int 80h
             ret

我还尝试将 getUserAction 中的代码放在“count”proc 中,但它没有任何改变。

UPD:对第一条评论的回答:在第二个“getUserAction”之后:

 mov eax, [buffer]
 cmp eax, 'u'    
 je setUsersValues
 cmp eax, 'e'
 je callFunc     
 call exit

UPD2:对不起,这里是所有代码

%define newline 10,0
%define A1 -7
%define A2 3
%define A3 2
%define A4 4
%define A5 2
SECTION .data
    labInfo     db "============Lab_3============",newline
    labInfoLen  equ $ - labInfo
    mainMenu    db "Choose the ex:",newline,\
            " r - call count",newline,\
            " t - call beep", newline,\
            " y - call exit func",newline
    mainMenuLen equ $ - mainMenu
    funcStr     db "Here func func func", newline
    funcStrLen  equ $ - funcStr
    countPromt  db "Please,choose the variant of variables value",newline,\
              " u - user defined values", newline,\
              " e - execerciese defined values", newline,\
              "Your choise:"
    promtLen    equ $ - countPromt
SECTION .bss
    buffer resb 1
    resultValue resb 1
%macro calculateFunc 5
     push eax
     push edx
     push ecx
         mov eax, %1
         mov ecx, %2
         add eax, ecx

         mov ecx, %3
         imul ecx

         mov ecx, %4
         xor edx, edx
         idiv ecx

         mov ecx, %5
         add eax, ecx
         mov [resultValue], eax
    pop ecx
    pop edx
        pop eax
%endmacro
SECTION .text
global _start
_start:
    ;call showPromt
    push labInfo
    push labInfoLen
    call printStr
    add esp, 8
    ;call showVarsList
    push mainMenu
    push mainMenuLen
    call printStr
    add esp, 8

    call getUserAction
    ;get get get action
    mov eax, [buffer]
    cmp eax, 'r'
    je count
    cmp eax, 't'
    je beep
    cmp eax, 'y'
    je exit
    jmp _start
count:
    ;showFuncInfo
    push funcStr
    push funcStrLen
    call printStr
    add esp, 8
    ;showProposal
    push countPromt
    push promtLen
    call printStr
    add esp, 8

    call getUserAction
    mov eax, [buffer]
    cmp eax, 'u'    
    je setUsersValues
    cmp eax, 'e'
    je callFunc 
    call exit
    ret
setUsersValues:
    nop; add some code later
        ret
callFunc:
    calculateFunc A1,A2,A3,A4,A5
    add byte [resultValue], '0'
    push resultValue
    push 1
    call printStr ; print Result
    add esp, 8
    ret
printStr:
    push ebp
    mov ebp, esp

    mov eax, 4
    mov ebx, 1
    mov ecx, [ebp+12]
    mov edx, [ebp+8] 
    int 80h

    pop ebp
    ret 
getUserAction:
    mov eax, 3
    mov ebx, 0
    mov ecx, buffer
        mov edx, 1
    int 80h
    ret
beep:
     nop;add some code later
     ret
exit:
    mov eax, 1
    xor ebx, ebx
    int 80h
4

1 回答 1

0

在没有看到所有代码的情况下,您的缓冲区应至少为 2 个字节。sys_read 和 sys_write 的大小都应该是 2 而不是 1。

于 2012-10-27T19:25:27.750 回答