我如何使用x86汇编code数组来代替一个字的信吗? [英] How do i use arrays in x86 assembly code to replace letters of a word?
问题描述
大家好让我的工作涉及组装数组赋值。我需要让用户输入一个数字,然后清除屏幕。之后,第二个玩家尝试猜词。我做过的一切,但我也有显示一个提示每次第二个玩家试图猜测。例如,如果我输入了单词Hello程序显示^ h!升!当第二个玩家试图猜测O操作。我已经尝试过了,但不能得到它的工作。任何帮助将是非常美联社preciated,谢谢你。
。数据选择:
.ascii输入密语\\ n
chose_length:
.INT 22lets_play_response:
.ascii尝试猜词进入\\ n
l_p_response_length:
.INT 30wrong_guess:
.ascii猜测不正确,请重试的\\ n
wrong_guess_length:
.INT 27正确:
.ascii正确的猜测,抓好\\ n
correct_length:
.INT 24Screen_Clearer:
.ascii\\ X1B [H \\ X1B [2J
Screen_Clearer_length:
.INT 11信:
。空间15
猜测:
。空间15。文本
。全球_start_开始:
MOV $选择,ECX%
MOV chose_length,EDX%
MOV $ 4,%EAX
MOV $ 1,EBX%
INT 0x80的$MOV $信,ECX%
MOV $ 15%EDX
MOV $ 3%EAX
MOV $ 0%EBX
INT 0x80的$调用Screen_ClearMOV $ lets_play_response,ECX%
MOV l_p_response_length,EDX%
MOV $ 4,%EAX
MOV $ 1,EBX%
INT 0x80的$#方法打印Word与替换每一秒的信!
#这是问题的一切作品区MOV $ 0%EDI循环:
CMP $ 4%EDI
JG结束 MOV $ 33信(%EDI)
加$ 1,%EDI
JMP环结束:
MOV $信,ECX%
MOV $ 4,%EAX
MOV $ 1,EBX%
RET方法#结束调用GuessLoopMOV $ 1,%eax中
INT 0x80的$GuessLoop:
MOV $猜测,ECX%
MOV $ 15%EDX
MOV $ 3%EAX
MOV $ 0%EBX
INT 0x80的$MOV猜测,ECX%
MOV字母,EDX%
CMP%ECX,EDX%
JNE不正确
JE正确不正确:
MOV $ wrong_guess,ECX%
MOV wrong_guess_length,EDX%
MOV $ 4,%EAX
MOV $ 1,EBX%
INT 0x80的$ JMP GuessLoop正确:
MOV $正确的,ECX%
MOV correct_length,EDX%
MOV $ 4,%EAX
MOV $ 1,EBX%
INT 0x80的$
RET#方法清除屏幕#
Screen_Clear:
MOV $ Screen_Clearer,ECX%
MOV Screen_Clearer_length,EDX%
MOV $ 4,%EAX
MOV $ 1,EBX%
INT 0x80的$
RET
方法#完清除屏幕
如果您要使用大会,你需要了解的寻址模式,<一个href=\"https://www.google.com/search?client=opera&q=memory%20addressing%20modes%20assembly&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggest\"相对=nofollow>在谷歌寻址模式
在此示例中,我用的是[基地+索引]模式。您将需要一个或多个变量来保存你的提示字符串。这不是AT&amp; T公司的语法,但它会给你的想法
%定义sys_exit 1
%定义SYS_WRITE 4
%定义SYS_READ 3
%限定了标准输入0
%定义标准输出1.bss段
提示RESB 15
信RESB 15
leter_len EQU $ - 信.text段
全球_start
_开始: MOV ECX,信
MOV EDX,leter_len
MOV EBX,标准输入
MOV EAX,SYS_READ
INT 80H MOV ESI,提示
MOV EDI,信
异或ECX,ECX
十二月EAX.MakeHint:
MOV DL,字节[EDI + ECX];从指针+指数得到字节
CMP DL,10;它是换行符
JE .ShowIt MOV字节[ESI + ECX],DL;移动字节到一丝缓冲
INC ECX;增加指数
CMP ECX,EAX;最后?
JE .ShowIt
MOV字节[ESI + ECX] 33;感动!下一个索引
INC ECX;增加指数
CMP ECX,EAX;在结束了吗?
JNE .MakeHint。展示下:
MOV ECX,提示
MOV EDX,leter_len
MOV EBX,标准输出
MOV EAX,SYS_WRITE
INT 80H MOV EAX,sys_exit
XOR EBX,EBX
INT 80H
Hey everyone so i am working on an assignment involving arrays in assembly. I need to have the user enter a number, then clear the screen. After that a second player tries to guess the word. I did all that but i also have to display a hint everytime the second player tries to guess. For example if i entered the word hello the program displays h!l!o when the second player tries to guess. I have tried it but cant get it to work. Any help would be much appreciated, thank you.
.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
If you are going to use Assembly, you will need to learn about Addressing Modes, Addressing Modes on Google
In this sample, I use the [Base + Index] mode. You will need one more variable to hold your hint string. It is not AT&T syntax, but it will give you the idea
%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
这篇关于我如何使用x86汇编code数组来代替一个字的信吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!