-1

大家好,所以我正在从事一项涉及装配中数组的任务。我需要让用户输入一个数字,然后清除屏幕。之后,第二个玩家尝试猜测这个词。我做了所有这些,但每次第二个玩家尝试猜测时,我也必须显示一个提示。例如,如果我输入了单词 hello,当第二个玩家尝试猜测时,程序会显示 h!l!o。我已经尝试过了,但无法让它工作。任何帮助将不胜感激,谢谢。

.data

chose:
    .ascii "Enter the Secret Word\n"
chose_length:
    .int 22

lets_play_response:
    .ascii "Try to Guess the Word Entered\n"
l_p_response_length:
    .int 30 

wrong_guess:
    .ascii "Incorrect Guess, Try Again\n"
wrong_guess_length:
    .int 27

correct:
    .ascii "Correct Guess, Good Job\n"
correct_length:
    .int 24

Screen_Clearer:
    .ascii "\x1B[H\x1B[2J"          
Screen_Clearer_length:              
    .int 11

letter:                                             
    .space 15                       
guess:
    .space 15                       

.text
.global _start

_start:
mov $chose, %ecx                
mov chose_length, %edx          
mov $4, %eax                    
mov $1, %ebx                    
int $0x80                       

mov $letter, %ecx               
mov $15, %edx                   
mov $3, %eax                    
mov $0, %ebx                    
int $0x80                       

call Screen_Clear               

mov $lets_play_response, %ecx   
mov l_p_response_length, %edx   
mov $4, %eax                    
mov $1, %ebx                    
int $0x80                       

# Method to Print Word With Every Second Letter Replaced With ! 
# This is the area with the problems everything else works

mov $0, %edi

Loop:
    cmp $4, %edi
    jg End 

    mov $33, letter (%edi)
    add $1, %edi
    jmp Loop

End:    
    mov $letter, %ecx
    mov $4, %eax
    mov $1, %ebx
    ret

# End of Method

call GuessLoop                  

mov $1, %eax                    
int $0x80                   

GuessLoop:                          
    mov $guess, %ecx                
    mov $15, %edx                   
    mov $3, %eax                    
    mov $0, %ebx                    
    int $0x80                       

mov guess, %ecx                 
mov letter, %edx                
cmp %ecx, %edx                  
jne Incorrect                   
je Correct                      

Incorrect:                          
    mov $wrong_guess, %ecx          
    mov wrong_guess_length, %edx    
    mov $4, %eax                    
    mov $1, %ebx                    
    int $0x80                       

    jmp GuessLoop                   

Correct:                            
    mov $correct, %ecx              
    mov correct_length, %edx        
    mov $4, %eax                    
    mov $1, %ebx                    
    int $0x80                       
    ret                             

# Method That Clears the Screen #
Screen_Clear:
    mov $Screen_Clearer, %ecx
    mov Screen_Clearer_length, %edx
    mov $4, %eax
    mov $1, %ebx
    int $0x80
    ret
# End of Method to Clear Screen
4

1 回答 1

0

如果你要使用 Assembly,你需要了解Addressing ModesAddressing Modes on Google

在此示例中,我使用 [Base + Index] 模式。您将需要一个变量来保存您的提示字符串。这不是 AT&T 语法,但它会给你的想法

%define sys_exit    1
%define sys_write   4
%define sys_read    3
%define stdin       0
%define stdout      1

SECTION .bss    
hint        resb    15
letter      resb    15
leter_len   equ $ - letter

SECTION .text
global _start
_start:

    mov     ecx, letter
    mov     edx, leter_len
    mov     ebx, stdin
    mov     eax, sys_read
    int     80H

    mov     esi, hint
    mov     edi, letter
    xor     ecx, ecx
    dec     eax

.MakeHint:
    mov     dl, byte [edi + ecx]        ; get byte from pointer + index
    cmp     dl, 10                      ; is it linefeed
    je      .ShowIt

    mov     byte[esi + ecx], dl         ; move byte into hint buffer
    inc     ecx                         ; increase index
    cmp     ecx, eax                    ; at the end?
    je      .ShowIt
    mov     byte[esi + ecx], 33         ; move ! to next index
    inc     ecx                         ; increase index
    cmp     ecx, eax                    ; at end?
    jne     .MakeHint

.ShowIt:
    mov     ecx, hint
    mov     edx, leter_len
    mov     ebx, stdout
    mov     eax, sys_write 
    int     80H

    mov     eax, sys_exit                
    xor     ebx, ebx                      
    int     80h      
于 2013-03-31T07:59:33.757 回答