Assembly 装配循环与增量
我有这个汇编任务,我需要写,我们需要做的任务是接受用户输入,循环遍历每个字符,统计字母、数字和杂项字符的数量 我发现最简单的方法是做三个独立的循环,一个用于计数数字,一个用于大写字母,一个用于小写字母,而不是通过从输入字符串长度中减去数字和字母计数来查找杂项计数 我在Assembly 装配循环与增量,assembly,x86,increment,Assembly,X86,Increment,我有这个汇编任务,我需要写,我们需要做的任务是接受用户输入,循环遍历每个字符,统计字母、数字和杂项字符的数量 我发现最简单的方法是做三个独立的循环,一个用于计数数字,一个用于大写字母,一个用于小写字母,而不是通过从输入字符串长度中减去数字和字母计数来查找杂项计数 我在.data部分将字母和数字计数变量定义为0,如下所示: acount: db 0 ; alphabetic count variable ncount: db 0
.data
部分将字母和数字计数变量定义为0
,如下所示:
acount: db 0 ; alphabetic count variable
ncount: db 0 ; numeric count variable
这样我就可以增加它们。我所有的循环都是以相同的方式设置的,因此以下是我的数字计数器示例:
init_numeric:
;; Initialize the input for scanning
mov ecx, [rlen] ; initialize the input length
mov esi, input ; point to the start of input
scan_numeric:
;; beginning of the character scan for numeric values
mov al, [esi] ; get a character
inc esi ; update to the next character
cmp al, '0' ; check the lower bound
jb not_num ; jump if below '0'
cmp al, '9' ; check the upper bound
ja not_num ; jump if above '9'
inc [ncount] ; add 1 to the numeric count
not_num:
dec ecx ; update the number of characters
jnz scan_numeric ; loop to top if more characters
一旦这些循环完成,我将获得杂项计数,它在.bss
部分中定义为:
mcount: resb 4 ; reserve space for misc character count
以及要在中查找的计算和操作:
get_misc:
;; Subtract the alphabetic and numeric counts from the length for
;; miscellanious character count
mov eax, [rlen] ; move the input string length
sub eax, [acount] ; subtract the alpha count
sub eax, [ncount] ; subtract the numeric count
mov [mcount], eax ; move eax value to mcount reserve
问题是,当我运行它时,用户输入非常好,但是inc
指令的操作大小未定义错误,但是当我使用dword
或word
定义它们时,我会得到错误
有什么帮助吗
编辑: 以下是我的输出提示和值部分:
result_write:
;; Write the results to the terminal
;; Alphabetic Count
mov eax, SYSCALL_WRITE ; write function
mov ebx, STDOUT ; file descripter
mov ecx, init ; initial response msg
mov edx, ilen ; initial msg length
int 080h ; kernel execution
mov eax, SYSCALL_WRITE ; write function
mov ebx, STDOUT ; file descripter
mov ecx, [acount] ; alphabetic count
mov edx, 4 ; length
int 080h ; kernel execution
mov eax, SYSCALL_WRITE ; write function
mov ebx, STDOUT ; file descripter
mov ecx, alpha ; alphabetic response end
mov edx, alen ; response length
int 080h ; kernel execution
这是按字母顺序的计数,另外两个用于数字和杂项。相同。您将
ncount
指向一个db
,而不是dw
或dd
,这就是为什么您不能使用inc-dword-ptr[ncount]
或inc-word-ptr[ncount]
。不过,您可以使用inc byte ptr[ncount]
或者,将
ncount
扩展到dw
并使用word ptr
,或者扩展到dd
并使用dword ptr我是否也需要更改mcount:resb 4
?这修复了错误,但现在没有数值在运行时写入终端。不,它正确地保留了4个字节(dword)。您还没有显示执行输出的部分代码,因此我们无法判断错误。也许你忘了转换成文本。提供并学习使用调试器。如何将其转换为文本?对不起,我是新来的。只需移动到注册并添加“0”,然后返回?