tyyfly 发表于 2025-4-17 20:41:38

实验9

在屏幕中間分別顯示綠色、綠底紅色、白底藍色的字符串'welcome to masm!'

A:
assume cs:codesg, ds:datasg
datasg segment
      db 'welcome to masm!'
datasg ends
codesg segment
      start:      mov ax,datasg
                        mov ds,ax
                        mov ax,0B872h
                        mov es,ax
                        mov bx,10h
                        mov si,0
                        mov di,0
                        
                        mov cx,10h
                s:      mov al,ds:
                        mov ah,00000010b
                        mov es:,ax
                        mov ah,00100100b
                        mov es:,ax
                        mov ah,00010111b
                        mov es:,ax
                        
                        inc si
                        add di,2
                        loop s
                        
                        mov ax,4c00h
                        int 21h
codesg ends
end start

FishC 发表于 2025-4-17 20:43:15

assume cs:codesg, ds:datasg

datasg segment
    db 'welcome to masm!'
datasg ends

codesg segment
start:
    mov ax, datasg
    mov ds, ax
    mov ax, 0B872h       ; 屏幕第12行中间显存地址
    mov es, ax
    mov si, 0            ; 字符串索引
    mov di, 0            ; 显存偏移

    mov cx, 16         ; 循环16次(字符串长度)
s:mov al,          ; 取字符
    ; 第一行:绿色字(02h)
    mov ah, 00000010B
    mov es:, ax
    ; 第二行:绿底红字(24h)
    mov ah, 00100100B
    mov es:, ax; +160到下一行
    ; 第三行:白底蓝字(71h)
    mov ah, 01110001B
    mov es:, ax; +320到下下彳

    inc si
    add di, 2            ; 每个字符占2字节
    loop s

    mov ax, 4c00h
    int 21h
codesg ends
end start

修正说明:
1. 显存地址计算:0B872h对应屏幕第12行中间位置
2. 三行颜色处理:
   - 00000010B 绿色字符
   - 00100100B 绿底红字
   - 01110001B 白底蓝字
3. 每行间隔160字节(显存每行160字节)
4. 使用di+160和di+320定位到第二、第三行

运行效果:会在屏幕中央显示三行不同颜色的"welcome to masm!"字符串

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
页: [1]
查看完整版本: 实验9