所以我的上一篇文章非常令人困惑,所以我想重新上传它以使其更加清晰。
基本上,我有一个长度为9个字符的字符串,我想让用户能够选择一个索引来改变字符" X"
我知道如何通过简单地在所需索引中进行硬编码来改变元素的值
; Changes index 1's value to X
mov eax, board ;board is the 9 character-long string
mov byte[eax+1], 'X'
我想知道的是我如何更改上面的陈述,而不是插入' X'进入用户指定的索引。
这是我到目前为止所尝试的内容
section .data
board db 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 ;Fills the array of size 9 with Spaces
board_len equ $ - board
section .bss
element resb 2 ;Reserves 2 bytes for user input. x1 for the number and x1 for the line feed
section .text
global _start
_start
; Prompt user for input
mov ecx, user_prompt
mov edx, user_prompt_len
call s_print
;Take in user input
mov ecx, element
mov edx, 2
call read_int
; convert string to integer
mov eax, [element]
sub eax, '0'
mov [element], eax
; Insert 'X' into the index specified
mov ebx, [element]
mov eax, board
mov byte[board+ebx], 'X'
;Print out board
mov ecx, board
mov edx, board_len
;Exit program
mov eax, 1
int 0x80
s_print:
;; Prints message placed in ECX
mov ebx, 1
mov eax, 4
int 0x80
ret
read_int:
mov ebx, 0
mov eax, 3
int 0x80
ret