【问题标题】:assembly code to scroll the screen one line down clearing the first line in the screen and then scrolls one line up if a key is pressed汇编代码向下滚动屏幕一行清除屏幕中的第一行,然后在按下键时向上滚动一行
【发布时间】:2015-11-08 21:01:10
【问题描述】:

我正在尝试向下滚动 1 行,然后向上滚动,但是 a) 我不知道如何测试这段代码 b)我不确定“按下键时”使用哪个中断

非常感谢您的帮助 这是我的代码:

Data_segment_name  segment  para 

firstline db 160 dup(0)




Data_segment_name ends


Stack_segment_name segment para stack



Stack_segment_name ends


Code_segment_name segment 

Main_prog  proc far

    assume SS:Stack_segment_name,CS:Code_segment_name,DS:Data_segment_name

    mov AX,Data_segment_name         ; load the starting address of the data
    mov DS,AX                        ; segment into DS reg. 

    ;code scroll down (clear first line) then scroll back up(restore cleared line)

    mov es,ax                        ;save first line
    lea di,firstline
    mov ax,0b800h
    mov ds,ax
    mov ax,0
    mov si,ax                        
    cld
    mov cx,80
    rep movsw                        ;save ends

    ;now let's scroll down :)

    mov ax,0b800h
    mov es,ax
    mov ax,0
    mov di,ax
    mov ax,160
    mov si,ax
    cld
    mov cx,24*80
    rep movsw

    ;now let's scroll up :)

    int 21h  ;check

    mov ax,160*24
    mov si,ax
    mov ax,160*25
    mov di,ax
    std
    mov cx,24*80
    rep movsw

    ;restore first line

    mov AX,Data_segment_name         ; load the starting address of the data
    mov DS,AX                        ; segment into DS reg. 
    lea si,firstline
    mov ax,0
    mov di,ax
    cld
    mov cx,80
    rep movsw


    mov ax,4c00h                     ; exit program
    int 21h


Main_prog      endp

Code_segment_name   ends
                end Main_prog

【问题讨论】:

    标签: windows assembly dos masm dosbox


    【解决方案1】:

    广告一):

    测试工具称为“调试器”。我推荐 Turbo Debugger(谷歌)。

    广告 b):

    Ralf Brown's interrupt listTechHelp 是很好的参考。一目了然:Int 10h 用于视频,Int 16h 用于键盘,Int 21h 用于 MS-DOS。

    您应该切换到简化的段指令.CODE.DATA.STACK 和过程编程PROCENDP。当您的项目发展壮大时,跟踪它会有所帮助。

    例子:

    .MODEL small
    .STACK 1000h
    
    .DATA
        firstline db 160 dup(0)
    
    .CODE
    save_firstline PROC
        push ds
        mov ax, ds
        mov es, ax
        lea di, firstline
        mov ax, 0b800h
        mov ds, ax
        mov ax, 0
        mov si, ax
        mov cx, 80
        rep movsw
        pop ds
        ret
    save_firstline ENDP
    
    restore_firstline PROC
        lea si, firstline
        mov ax, 0b800h
        mov es, ax
        mov ax, 0
        mov di, ax
        mov cx, 80
        rep movsw
        ret
    restore_firstline ENDP
    
    scroll_up PROC
        call save_firstline
        mov ah, 6               ; http://www.ctyme.com/intr/rb-0096.htm
        mov al, 1               ; number of lines to scroll
        mov bh, 0               ; attribute
        mov ch, 0               ; row top
        mov cl, 0               ; col left
        mov dh, 25              ; row bottom
        mov dl, 80              ; col right
        int 10h
        ret
    scroll_up ENDP
    
    scroll_down PROC
        mov ah, 7               ; http://www.ctyme.com/intr/rb-0097.htm
        mov al, 1               ; number of lines to scroll
        mov bh, 0               ; attribute
        mov ch, 0               ; row top
        mov cl, 0               ; col left
        mov dh, 25              ; row bottom
        mov dl, 80              ; col right
        int 10h
        call restore_firstline
        ret
    scroll_down ENDP
    
    main PROC
        mov ax, @data
        mov ds, ax
    
        waitForKey:             ; http://webpages.charter.net/danrollins/techhelp/0229.HTM
            mov   ah, 1
            int   16h
            jnz   gotKey        ; jmp if key is ready
            jmp   waitForKey    ; loop back and check for a key
        gotKey:
            mov ah, 0           ; key is ready, get it
            int 16h             ; now process the key
    
        cmp ah, 48h             ; <UP>
        jne @F
        call scroll_up
        jmp waitforKey
    
        @@:
        cmp ah, 50h             ; <DOWN>
        jne @F
        call scroll_down
        jmp waitForKey
    
        @@:
        cmp al, 1Bh             ; <ESC>
        jne waitForKey
    
        mov ax, 4C00h
        int 21h
    
    main ENDP
    
    END main 
    

    【讨论】:

    • 抱歉回复晚了,感谢您提供的参考资料,但我想我不明白您在那里做了什么? “您应该切换到简化的段指令 .CODE、.DATA、.STACK 并切换到过程编程 PROC、ENDP” 这是否类似于在 c++ 中编写函数? @rkhb
    • @Nemo:是的。我检查了 Googleable 准确性的条款;-) - “简化的段指令”和“过程编程”是两个不同的东西。使用前者,您可以让汇编程序定义段。示例程序完成。复制它,组装并链接它。运行、调试并尽可能多地从中学习。
    • 非常感谢我阅读了代码并理解了大部分内容。使用中断向上和向下滚动要容易得多。但是有一个问题,我无法运行代码。我得到五个严重的错误。 @F 和 @@ 未定义。这些应该是特定跳跃的标签吗?
    • @Nemo:你用 标记了这个问题。 MASM 理解@F 和@@。 @F 的意思是:“到下一个@@”(F = 前进)。对于不同的汇编器,将第一个 jne @F 更改为 jne J1,将第一个 @@: 更改为 J1:,将第二个 jne @F 更改为 jne J2,将第二个 @@: 更改为 J2
    • 我不知道为什么它不起作用。我正在运行的应用程序名为 MASM @rkhb
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 2017-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多