编写汇编代码,存储屏幕上写的内容,清除屏幕,然后恢复写入的内容

时间:2014-11-22 17:35:05

标签: assembly masm dosbox

我需要编写汇编代码,用于存储在文本模式下在屏幕上写入的内容(在dosbox中),清除屏幕然后恢复以前写的内容,所以我编写了这段代码但它看起来并不像工作正常..谁能指出为什么?我会非常感激

PS:我还是个菜鸟

这是我的代码:

Dataseg segment
    Data_seg dw 2000 dup(?)
Dataseg ends


Codeseg segment

Main PROC  far   

            assume ds:Dataseg,cs:Codeseg,ss:stackseg

        Mov ax,Data_seg
        Mov es,ax
        Mov ax,0b800h
        Mov ds,ax       
        Mov cx,25*80 ;(rows)*cols-default for screen

        Mov di,OFFSET Data_seg
        Mov si,0   
        CLD             ;autoincrement
        Rep movsw


        ;now clearing the screen

        Mov cx,25*80
        Mov ax,0b800h
        Mov es,ax
        Mov ax,0720h
        Mov di,0
        Rep stosw


        ;now restoring the contents of the screen
       Mov ax,Data_seg
       Mov ds,ax
       Mov cx,25*80
       Mov di,0
       Mov si,OFFSET Data_seg
       Rep movsw





     Mov Ah,4ch
     Int 21h


Main endp
Codeseg ends
     end Main

2 个答案:

答案 0 :(得分:0)

您混淆了“数据集”(段名称)和“Data_seg”(变量名称)。 Mov ax,Data_seg加载变量Data_seg偏移量该段。加载细分有两种选择:

Mov ax, SEG Data_seg    ; Load the segment of variable Data_seg

Mov ax, Dataseg         ; Load the segment called "Dataseg" 

答案 1 :(得分:0)

替换:

Mov ax,Data_seg
Mov es,ax
Mov ax,0b800h
Mov ds,ax
Mov di,OFFSET Data_seg
    Mov si,0

由:

push cs
pop es
mov di, OFFSET Data_seg
Mov ax,0b800h
Mov ds,ax 
xor si, si ;set pointer to the beginning of the screen

替换:

   Mov ax,Data_seg
   Mov ds,ax
   Mov cx,25*80
   Mov di,0
   Mov si,OFFSET Data_seg
   Rep movsw

由:

   push cs
   pop ds
   mov ax, 0b800h
   mov es, ax
   Mov cx,25*80
   Mov di, 0
   Mov si,OFFSET Data_seg
   Rep movsw