1. 实验任务1

assume cs:code, ds:data
data segment
    db 'welcome to masm!';字符串
    db 2h,24h,71h;颜色
data ends

code segment
start:
    mov ax,data
    mov ds,ax
    mov ax,0b800h
    mov es,ax
    mov si,1824;首位字符地址
    mov cx,3
    mov bx,0
s:  push cx
    mov cx,16
    mov di,0
s0: mov al,ds:[di];控制数据
    mov ah,ds:[bx+16];控制颜色
    mov es:[si],ax;放入显示区
    inc di
    inc si
    inc si
    loop s0
    inc bx;下一个颜色
    add si,128;下一行
    pop cx
    loop s
    mov ah,4ch
    int 21h
code ends
end start

 

2. 实验任务2

assume cs:code, ds:data
data segment
    ;str db 'try', 0
    str db 'another try', 0 
data ends

code segment
start:  
    mov ax, data
    mov ds, ax

    mov si, offset str
    ;mov al, 2
    mov al, 4 
    call printStr

    mov ah, 4ch
    int 21h

printStr:
    push bx
    push cx
    push si
    push di

    mov bx, 0b800H
    mov es, bx
    mov di, 0
s:      mov cl, [si]
    mov ch, 0
    jcxz over
    mov ch, al
    mov es:[di], cx
    inc si
    add di, 2
    jmp s

over:   pop di
    pop si
    pop cx
    pop bx
    ret

code ends
end start

  • push命令是为了保存之前操作过的的相关寄存器的值到栈中,pop命令是在程序相关操作结束后,将这些值出栈到对应的寄存器
  • 将str段的数据存入低位,颜色存入高位,然后放入显示缓冲区中

3. 实验任务3

assume cs:code, ds:data
data segment
    x dw 1984
    str db 16 dup(0)
data ends
code segment
start: 
    mov ax, data
    mov ds, ax
    mov ax, x
    mov di, offset str
    call num2str
    mov ah, 4ch
    int 21h
num2str:
    push ax
    push bx
    push cx
    push dx
   
    mov cx, 0
    mov bl, 10
s1:   
    div bl
    inc cx
    mov dl, ah
    push dx
    mov ah, 0
    cmp al, 0
    jne s1
s2:    
    pop dx
    or dl, 30h
    mov [di], dl
    inc di
    loop s2
   
    pop dx
    pop cx
    pop bx
    pop ax
    ret
code ends
end start

assume cs:code, ds:data
data segment
        x dw 1984
        str db 16 dup(0)
data ends

code segment
start:  
        mov ax, data
        mov ds, ax
        mov ax, x
        mov di, offset str
        call num2str
        
        mov si, offset str
        mov al, 2
        call printStr
        
        mov ah, 4ch
        int 21h

num2str:
        push ax
        push cx
        push dx
        
        mov cx, 0
        mov bl, 10
s1:      
        div bl
        inc cx
        mov dl, ah
        push dx
        mov ah, 0
        cmp al, 0
        jne s1
s2:        
        pop dx
        or dl, 30h
        mov [di], dl
        inc di
        loop s2
        
        pop dx
        pop cx
        pop ax
        
        ret
        
printStr:
        push bx
        push cx
        push si
        push di
        
        mov bx,0B800H
        mov es,bx
        mov di, 0
s:        mov cl,[si]
        mov ch,0
        jcxz over
        mov ch,al
        mov es:[di], cx
        inc si
        add di, 2
        jmp s

over: 
        pop di
        pop si
        pop cx
        pop bx
        
        ret
code ends
end start

4. 实验任务4

assume cs:code, ds:data
data segment
        str db 80 dup(?)
data ends

code segment
start:  
        mov ax, data
        mov ds, ax
        mov si, 0

s1:        
        mov ah, 1
        int 21h
        mov [si], al
        cmp al, '#'
        je next
        inc si
        jmp s1
next:
        mov cx, si
        mov si, 0
s2:     mov ah, 2
        mov dl, [si]
        int 21h
        inc si
        loop s2

        mov ah, 4ch
        int 21h
code ends
end start

  • line12-19:从键盘输入单个字符,读入键盘输入,与‘#’比较,遇到#跳转到next执行
  • line21-27:将‘#’之前录入的内容输出。

5. 实验任务5

汇编语言数据的值由寄存器传递,通过栈的方式存储

posted on 2020-12-18 12:49  Nibelungenlied  阅读(70)  评论(1编辑  收藏  举报