请问我是新的汇编语言,我正在尝试打印一个方框的轮廓。我真的被卡住了。尝试了我所知道的一切,但我不能让它打印出轮廓。提前感谢您的帮助
INCLUDE Irvine32.inc
.data
prompt BYTE "This program draws a rectangle using the * character.", 0
len BYTE "How high would you like your box? ", 0
wid BYTE "How wide would you like your box?: ", 0
image BYTE "* ", 0
space BYTE " ", 0
leninput DWORD ?
widinput DWORD ?
h DWORD ?
w DWORD ?
count DWORD ?
.code
main proc
;;; Write the prompt to the screen
mov edx, OFFSET prompt
call WriteString
call Crlf
;;; Write the length request to the screen
mov edx, OFFSET len
call Crlf
call WriteString
;;; Obtain the length value(which will be in eax)
call ReadDec
mov leninput, eax
;;; Write the width request to the screen
mov edx, OFFSET wid
call Crlf
call WriteString
;;; Obtain the second value(which will be in eax)
call ReadDec
mov widinput, eax
;;; Draw rectangle on screen
mov eax, 0
mov ecx, leninput; set outer loop with length
L1 :
mov count, ecx; save outer loop count
mov ecx, widinput; set inner loop count with the width
L2 :
call ConditionCheck
loop L2; repeat the inner loop
call Crlf; Print line
mov ecx, count; restore outer loop(length)
loop L1; repeat outer loop 1
exit
main endp
; ----------------------------------------------------------------------
ConditionCheck PROC
mov eax, leninput
mov ebx, widinput
.IF eax == 1
mov edx, OFFSET image
call WriteString
.ELSEIF eax == leninput
mov edx, OFFSET image
call WriteString
.ELSEIF ebx == 1
mov edx, OFFSET image
call WriteString
.ELSEIF ebx == widinput
mov edx, OFFSET image
call WriteString
.ELSE
mov edx, OFFSET space
call WriteString
.ENDIF
ret
ConditionCheck ENDP
; ---------------------------------------------------------------------- -
end main
输出应如下所示:
How high would you like your box? 5
How wide would you like your box? 6
******
* *
* *
* *
******
但我填好了这个盒子
答案 0 :(得分:0)
image
和space
应具有相同数量的字符:
image BYTE "* ", 0
space BYTE " ", 0
在ConditionCheck
EAX
和EBX
过程中,请将 循环的当前值指向不可更改的值leninput
和widinput
。所以改变
mov eax, leninput
mov ebx, widinput
到
mov eax, count
mov ebx, ecx