【发布时间】:2016-10-18 17:01:56
【问题描述】:
我正在做一项家庭作业,我需要在屏幕上随机打印 20 行 20 个 RANDOM 字符。我对汇编语言非常陌生,不明白为什么我的循环不会结束,即使我将 ecx 设置为 20 并且每次都在递减。
目前屏幕可以正确打印随机字母,但不会停止打印。
我的代码如下:
INCLUDE Irvine32.inc
.data
buffer byte 20 dup(?) ;buffer of size 20 initialized ?
L dword 20 ;length of size 20
.code
main proc
l1:
mov ecx,L ;ecx = 20
call RandomString ;call Random String
dec ecx ;ecx --
cmp ecx,0 ;compare ecx to zero
jne l1 ;jump if not equal back to l1
call WaitMsg ;press any button to continue
exit
main endp
RandomString PROC USES eax ecx edx
mov eax,26 ;eax = 26
call RandomRange ;call RandomRange
add eax, 'A' ;eax = random number between 0 and 25 + 'A'
mov buffer,al ;buffer = random letter
mov edx, OFFSET buffer ;edx = address of buffer
call WriteString ;write string to console
ret
RandomString ENDP
end main
【问题讨论】:
标签: loops assembly masm irvine32