Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to stop text at screen borders?
    primarykey
    data
    text
    <p>I'm making this little program where I have to move an asterisk around the screen. The problem is that every time it hits a border, I get an extra asterisk. Any help in how to get rid of that extra asterisk? It's a really simple program.</p> <p>Here's my code so far:</p> <pre><code>.model small .stack 256 .data row db 10 ;Save the initial cursor coordinates in col db 40 ;col and row. msg1 db "*",'$' ;Asterisk to be used by the program. msg2 db " ",'$' mSetCursor macro ;Macro for placing the cursor in the screen. ;pre-conditions ; ; None ; ;post-conditions ; ; Asterisks will be printed on the screen, ; depending on the location of the cursor. push ax push bx push dx mov bh,0 mov ah,2 mov dh,row mov dl,col int 10h pop dx pop bx pop ax endm .code main proc mov ax,@data mov ds,ax mov ax,03 ;Clean the screen. int 10h start: mSetCursor ;Call the macro in charge of placing ;the asterisk on the screen. mov ah,10h int 16h cmp ah,2dh ;Using the scan code of the letter X, we end je exit ;the program once the "X" key is pressed. cmp ah,0bh ;Using the scan code of the number 0, we clean je clear ;the screen once the "0" key is pressed. cmp ah,4bh ;Using the scan code of the left arrow, je left ;we use the left arrow key to move the asterisk left. cmp ah,48h ;Using the scan code of the up arrow, je up ;we use the up arrow key to move the asterisk up. cmp ah,4Dh ;Using the scan code of the right arrow, je right ;we use the right arrow key to move the asterisk right. cmp ah,50h ;Using the scan code of the down arrow, je down ;we use the down arrow key to move the asterisk down. mov ah,9 ;Code in charge of receiving the fifth message mov dx, offset msg2 ;This code ensures that nothing happens while int 21h ;keys that aren't arrow keys, 0, or X (quit) are pressed. jmp start left: ;We receive the asterisk, and decrease the value of col mov ah,9 ;This starts the leftward movement of the asterisk. mov dx, offset msg1 ;Finally, we skip to the Start label. int 21h dec col cmp col,00 ;Disallow that the asterisk move past the je right ;left side of the screen. jmp start right: ;Receive the asterisk, and increase the value of col. mov ah,9 ;This starts the rightward movement of the asterisk. mov dx, offset msg1 ;Finally, we skip to the Start label. int 21h inc col cmp col,79 ;Disallow that the asterisk move past the je left ;right side of the screen. jmp start down: ;We receive the asterisk and increase the value of row. mov ah,9 ;This starts the downward movement of the asterisk. mov dx, offset msg1 ;Finally, we jump to the Start label. int 21h inc row cmp row,24 ;Disallow that the asterisk move past the je up ;bottom of the screen. jmp start up: ;We receive the asterisk, and decrease the value of row. mov ah,9 ;This starts the upward movement of the asterisk. mov dx, offset msg1 ;Finally, we jump to the Start label. int 21h dec row cmp row,-1 ;Disallow that the asterisk move past the je down ;top of the screen. jmp start clear: mov ax,03 ;Clean the screen. int 10h jmp start exit: ;Label that lets us end the program. mov ah,4ch int 21h main endp end main </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload