2017-03-17 44 views
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 
****** 
* * 
* * 
* * 
****** 

,但我有填充,而不是

+0

啊.. MASM宏或指令,或者是什么'.IF'是......那一定是不方便调试,看不清真正的指令。顺便说一句,你是否考虑过会发生什么,如果你愿意'leninput - = 2;',总是输出一个完整的行,然后用'inner'行执行'leninput'循环,并且循环结束后再输出一个完整行? (但是,你可能应该对输入进行清理以确认它是3+),同样的,在'widinput - = 2;'处理后,内部代码可能会更简单。 – Ped7g

回答

0

imagespace箱应该有相同的字符数量:

image BYTE "* ", 0 
space BYTE " ", 0 

在程序ConditionCheckEAXEBX指的是当前而不是的值到不可更改的值leninputwidinput。因此,改变

mov eax, leninput 
mov ebx, widinput 

mov eax, count 
mov ebx, ecx