私は、異なるサイズの四角形を画面の異なる領域に印刷するタスクを持っています。私は、各正方形が他の正方形から等しく離れているようにしたい。あなたが見ることができるように、各広場間の距離は常に減少します。私は、問題は私がlengthOFside
AX
にを更新するとき、それは変更されないということだと思います 異なるサイズの四角形を隣り合わせに印刷する
:これは私の結果です。その他の先端ははるかに高く評価されます:)ここではコードです:lengthOFsideは5の固定値を持っているので
; multi-segment executable file template.
newline=160 ;number of chars to move to next line
col = 2 ;each column is another charachter
lengthOFside = 5 ;side of square, grows each time of the loop
numRow = 5 ;which row to start from
numCol = 30 ;which col to start from
numSquares = 4 ;number of squares
data segment
; add your data here!
pkey db "press any key...$"
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov AX,0B800H
MOV ES,AX
; add your code here
;first print
MOV DH, numSquares ;number of squares I want to print
MOV AX,lengthOFside
MOV BL,numRow ;number line
MOV BH,numCol ;num col
MOV CX,lengthOFside ;length of one side
CALL print_square ;CALL the function that prints the square
DEC DH
loopPrint:
lengthOFside = ax
ADD BH,lengthOFside+2 ; move right lengthOFside times.
ADD AX,2
MOV CX,AX
CALL print_square ;print square
DEC DH
jnz loopPrint
lea dx, pkey
mov ah, 9
int 21h ; output string at ds:dx
; wait for any key....
mov ah, 1
int 21h
mov ax, 4c00h ; exit to operating system.
int 21h
print_square: ;get (x,y) as (bh,bl) and cx = length of one side. Prints a square from that point.
MOV SI,0
PUSH BX
CALL Get2startpoint ;get to starting point
POP BX
PUSH CX
CALL Horizontal_Line ;print the first horizontal line
POP CX
PUSH CX
CALL Vertical_Line ;print the first vertical line
POP CX
PUSH BX
CALL Get2startpoint ;return to starting point
POP BX
PUSH CX
call Vertical_Line ;print another vertical line
POP CX
PUSH CX
SUB SI,newline ;we do because the function vertical line adds new line every END of it's loop.
;So SI is on the next line so the vertical line will be n+1. so we decrease one line from si
CALL Horizontal_Line ;print anohter horizontal line
POP CX
RET
Vertical_Line:
ADD SI,newline ;prints vertical line adds to si 160 after printing *
DEC CX ;prints vertical line adds to si 160 after printing *
LOOP2: ;prints vertical line adds to si 160 after printing *
MOV ES:[SI],'*' ;prints vertical line adds to si 160 after printing *
ADD si,newline ;prints vertical line adds to si 160 after printing *
LOOP LOOP2 ;prints vertical line adds to si 160 after printing *
RET
Horizontal_Line: ;add si,2 to get to the next data cell and insert *
MOV ES:[SI],'*' ;add si,2 to get to the next data cell and insert *
DEC CX ;add si,2 to get to the next data cell and insert *
LOOP1: ;add si,2 to get to the next data cell and insert *
ADD SI,2 ;add si,2 to get to the next data cell and insert *
MOV ES:[SI],'*' ;add si,2 to get to the next data cell and insert *
LOOP LOOP1 ;add si,2 to get to the next data cell and insert *
RET
Get2startpoint: ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
MOV SI,0 ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
ADD_NEW_LINE: ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
ADD SI,newline ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
DEC BL ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
JNZ ADD_NEW_LINE ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
SKIP_TO_COL: ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
ADD SI,col ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
DEC BH ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
JNZ SKIP_TO_COL ;gets (x,y) as <bh,bl> and gets to the point where it should start printing the square
RET
ends
end start ; set entry point and stop the assembler.
あなたのご意見は、私の目を傷つける
は
AX
レジスタにある側の現在長さに加えて相対してください! :)とにかく、デバッガを使用してコードをステップ実行し、どこが間違っているかを確認します。 – Jester@Jesterの問題は、私のソフトウェアでどのようにデバッグするのか分かりません。そして、そういうコメントも私を傷つけます:) – user6219654
http://courses.ee.sun.ac.za/OLD/2003/Rekenaarstelsels245/8086_Instruksies/emulator.html – Ped7g