Moving a character back and forth across the monitor

末鹿安然 提交于 2021-02-17 06:04:42

问题


Write a program that will move a character from left to right and then back again across the monitor of the PC a number of times as specified by the user's input. The user is to be prompted for the character to display and how many times to move it back and forth. An input of '?' and 1 would cause the '?' to move back and forth across the monitor 1 trip.

Your program must only allow entry of numbers from 1 to 4 inclusive. Use a loop that allows an exit only if the value is greater than zero and less than four. If the user enters an illegal value you must remind him/her of the values that are allowed and re-prompt for the numeric value. You do not have to do any error checking on the character as any printable character is fine.

Remember if you have just displayed a character the cursor will be just to the right of it. In order to display the next character you will have to erase the previous character and then display the character in the new location. The backspace character is character number 8 and a space is character number 32. Do not display a character in the 80th position as this will cause the cursor to advance to the next line. All output must be on the same line.

You will also have to write a procedure that will slow the cursor movement across the screen. A modern CPU will move the cursor so fast that the user will not see it move. Your delay procedure needs to be a loop that does nothing an appropriate number of times.

Here is the current program I have in which character "!" is just moving from left to right on the screen

    include PCMAC.Inc

    .MODEL SMALL

    .586
    .STACK 100h
    .DATA

theChar DB "!"

    .CODE

Delay   PROC

    push cx

        mov cx,0

For_2:  NOP

        dec cx

        jnz For_2

        pop cx

        ret 



Delay   ENDP



MAIN  PROC

        _Begin

        mov cx, 79 ;  display the char 79 times

For_1:  _PutCh  theChar

        call Delay

        _PutCh 8

        _PutCh 32

        dec cx

        jnz For_1

        _EXIT 0

MAIN  ENDP


END MAIN ; 

来源:https://stackoverflow.com/questions/64511980/moving-a-character-back-and-forth-across-the-monitor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!