0
請我是新的彙編語言,我正在嘗試打印一個框的大綱。我很困難。嘗試瞭解我所知道的一切,但我無法打印出輪廓。預先感謝您的幫助如何用匯編語言打印框大綱
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
******
* *
* *
* *
******
,但我有填充,而不是
啊.. MASM宏或指令,或者是什麼'.IF'是......那一定是不方便調試,看不清真正的指令。順便說一句,你是否考慮過會發生什麼,如果你願意'leninput - = 2;',總是輸出一個完整的行,然後用'inner'行執行'leninput'循環,並且循環結束後再輸出一個完整行? (但是,你可能應該對輸入進行清理以確認它是3+),同樣的,在'widinput - = 2;'處理後,內部代碼可能會更簡單。 – Ped7g