MOVS EXAMPLE – SCREEN SCROLLING

MOVS has the two forms MOVSB and MOVSW. REP allows the instruction to be repeated CX times allowing blocks of memory to be copied. We will perform this copy of the video screen.

assembly language programming  MOVS EXAMPLE – SCREEN SCROLLING

Scrolling is the process when all the lines on the screen move one or more lines towards the top of towards the bottom and the new line that appears on the top or the bottom is cleared. Scrolling is a process on which string movement is naturally applicable. REP with MOVS will utilize the full processor power to do the scrolling in minimum time.

In this example we want to scroll a variable number of lines given as argument. Therefore we have to calculate the source address, which is 160 times the number of lines to clear. The destination address is 0, which is the top left of the screen. The lines that scroll up are discarded so the source pointer is placed after them. An equal number of lines at the bottom are cleared. These lines have actually been copied above.

Example 7.5
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 ; scroll up the screen[org 0x0100] jmp start ; subroutine to scroll up the screen; take the number of lines to scroll as parameterscrollup: push bpmov bp,sppush axpush cxpush sipush dipush espush ds mov ax, 80 ; load chars per row in axmul byte [bp+4] ; calculate source positionmov si, ax ; load source position in sipush si ; save position for later useshl si, 1 ; convert to byte offsetmov cx, 2000 ; number of screen locationssub cx, ax ; count of words to move mov ax, 0xb800 mov es, ax ; point es to video basemov ds, ax ; point ds to video basexor di, di ; point di to top left columncld ; set auto increment mode rep movsw ; scroll upmov ax, 0×0720 ; space in normal attributepop cx ; count of positions to clearrep stosw ; clear the scrolled space pop ds pop es pop di pop si pop cx pop ax pop bpret 2 start: mov ax,5push ax ; push number of lines to scrollcall scrollup ; call the scroll up subroutine mov ax, 0x4c00 ; terminate programint 0×21

The beauty of this example is that the two memory blocks are overlapping. If the source and destination in the above algorithm are swapped in an expectation to scroll down the result is strange. For example if 5 lines were to scroll down, the top five lines of the screen are repeated on the whole screen. This is where the use of the direction flag comes in.

When the source is five lines below the destination, the first five lines are copied on the first five lines of the destination. However the next five lines to be copied from the source have been destroyed in the process; because they were the same as the first five lines of the destination. The same is the problem with every set of five lines as the source is destroyed during the previous copy. In this situation we must go from bottom of the screen towards the top. Now the last five lines are copied to the last five lines of the destination. The next five lines are copied to next five lines of the destination destroying the last five lines of source; but now these lines are no longer needed and have been previously copied. Therefore the copy will be appropriately done in this case.

We give an example of scrolling down with this consideration. Now we have to calculate the end of the block instead of the start.

Example 7.6
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 ; scroll down the screen[org 0x0100] jmp start ; subroutine to scrolls down the screen; take the number of lines to scroll as parameterscrolldown: push bpmov bp,sppush axpush cxpush sipush dipush espush ds mov ax, 80 ; load chars per row in axmul byte [bp+4] ; calculate source positionpush ax ; save position for later useshl ax, 1 ; convert to byte offsetmov si, 3998 ; last location on the screensub si, ax ; load source position in simov cx, 2000 ; number of screen locationssub cx, ax ; count of words to move mov ax, 0xb800 mov es, ax ; point es to video basemov ds, ax ; point ds to video basemov di, 3998 ; point di to lower right columnstd ; set auto decrement mode rep movsw ; scroll upmov ax, 0×0720 ; space in normal attributepop cx ; count of positions to clearrep stosw ; clear the scrolled space pop ds pop es pop di pop si pop cx pop ax pop bpret 2 start: mov ax,5push ax ; push number of lines to scrollcall scrolldown ; call scroll down subroutine mov ax, 0x4c00 ; terminate programint 0×21
VN:F [1.9.14_1148]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.14_1148]
Rating: 0 (from 0 votes)