鱼C论坛

 找回密码
 立即注册
查看: 2497|回复: 2

小白求助

[复制链接]
发表于 2018-12-16 17:29:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
第一个题目:计算从1到20的累加和,以十进制的方式显示在屏幕上
第二个题目:在80*25的屏幕上,以多种颜色显示多种字符
求大佬这两道题怎么写?
还有DOSBox 0.74怎么在屏幕上显示程序运行结果?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-12-16 22:45:36 | 显示全部楼层
assume cs:code, ds:data

data segment
buf        db 512 dup(?)
stack        db 512 dup(?)
stack_top:
data ends

code segment
; void PutChar(uint8_t x, uint8_t y, char ch, uint8_t attr);
PutChar:
        push        bp
        mov        bp, sp
        push        di
        push        es
        
        mov        ax, 0b800h
        mov        es, ax
        mov        dl, [bp + 6]        ; y
        mov        al, 160
        mul        dl
        mov        di, ax
        mov        dl, [bp + 4]        ; x
        mov        al, 2
        mul        dl
        add        di, ax
        
        mov        al, [bp + 8]        ; ch
        mov        ah, [bp + 10]        ; attr
        mov        es:[di], ax
        
        mov        bh, 0        ; 显示页码
        mov        dh, [bp + 6]        ; y
        mov        dl, [bp + 4]        ; x
        add        dl, 1
        mov        ah, 2        ; 设置光标位置
        int        10h
        
        pop        es
        pop        di
        mov        sp, bp
        pop        bp
        ret

; void PutString(uint8_t x, uint8_t y, char *str, uint8_t attr);
PutString:
        push        bp
        mov        bp, sp
        push        bx
        push        si
        push        di
        
        mov        si, [bp + 4]        ; x
        mov        di, [bp + 6]        ; y
        mov        bx, [bp + 8]        ; str
@@:
        cmp        byte ptr [bx], 0
        je        @F
        push        [bp + 10]        ; attr
        xor        ah, ah
        mov        al, [bx]
        push        ax                ; ch
        push        di                ; y
        push        si                ; x
        call        PutChar
        add        sp, 8
        inc        si
        inc        bx
        jmp        @B
@@:
        pop        di
        pop        si
        pop        bx
        mov        sp, bp
        pop        bp
        ret

; void NumberToString(uint16_t number, char *buffer);
NumberToString:
        push        bp
        mov        bp, sp
        push        bx
        push        si
        push        di
        
        mov        di, [bp + 6]        ; buffer
        mov        ax, [bp + 4]        ; number
        xor        dx, dx
        ;mov        cx, 16
        mov        cx, 10                ; 现在是要十进制
@@:
        div        cx
        mov        dh, dl
        add        dl, '0'
        cmp        dh, 10
        jb        @1
        mov        dl, dh
        sub        dl, 10
        add        dl, 'A'
@1:
        mov        [di], dl
        inc        di
        xor        dx, dx
        cmp        ax, 0
        jne        @B
        mov        byte ptr [di], 0        ; '\0'
        
        ; 下面翻转字符串
        dec        di
        mov        si, [bp + 6]        ; buffer
@@:
        cmp        si, di
        jge        @F
        mov        ah, [si]
        mov        al, [di]
        mov        [si], al
        mov        [di], ah
        inc        si
        dec        di
        jmp        @B
@@:
        pop        di
        pop        si
        pop        bx
        mov        sp, bp
        pop        bp
        ret
start:
        mov        ax, data
        mov        ds, ax
        mov        ss, ax
        mov        sp, stack_top
        
        mov        cx, 1
        xor        ax, ax
L:
        add        ax, cx
        inc        cx
        cmp        cx, 20
        jbe        L
        
        mov        bx, offset buf
        push        bx                ; buffer
        push        ax                ; number
        call        NumberToString
        add        sp, 4
        
        mov        ax, 07h
        push        ax                ; attr
        mov        ax, offset buf
        push        ax                ; str
        xor        ax, ax
        push        ax                ; y
        push        ax                ; x
        call        PutString
        add        sp, 8
        
        mov        ax, 4c00h
        int        21h
code ends
end start
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-12-16 22:52:58 | 显示全部楼层
assume cs:code, ds:data

data segment
msg0        db 'C', 0
msg1        db 'C++', 0
msg2        db 'Java', 0
msg3        db 'Python', 0

stack        db 512 dup(?)
stack_top:
data ends

code segment
; void PutChar(uint8_t x, uint8_t y, char ch, uint8_t attr);
PutChar:
        push        bp
        mov        bp, sp
        push        di
        push        es
        
        mov        ax, 0b800h
        mov        es, ax
        mov        dl, [bp + 6]        ; y
        mov        al, 160
        mul        dl
        mov        di, ax
        mov        dl, [bp + 4]        ; x
        mov        al, 2
        mul        dl
        add        di, ax
        
        mov        al, [bp + 8]        ; ch
        mov        ah, [bp + 10]        ; attr
        mov        es:[di], ax
        
        mov        bh, 0        ; 显示页码
        mov        dh, [bp + 6]        ; y
        mov        dl, [bp + 4]        ; x
        add        dl, 1
        mov        ah, 2        ; 设置光标位置
        int        10h
        
        pop        es
        pop        di
        mov        sp, bp
        pop        bp
        ret

; void PutString(uint8_t x, uint8_t y, char *str, uint8_t attr);
PutString:
        push        bp
        mov        bp, sp
        push        bx
        push        si
        push        di
        
        mov        si, [bp + 4]        ; x
        mov        di, [bp + 6]        ; y
        mov        bx, [bp + 8]        ; str
@@:
        cmp        byte ptr [bx], 0
        je        @F
        push        [bp + 10]        ; attr
        xor        ah, ah
        mov        al, [bx]
        push        ax                ; ch
        push        di                ; y
        push        si                ; x
        call        PutChar
        add        sp, 8
        inc        si
        inc        bx
        jmp        @B
@@:
        pop        di
        pop        si
        pop        bx
        mov        sp, bp
        pop        bp
        ret

start:
        mov        ax, data
        mov        ds, ax
        mov        ss, ax
        mov        sp, stack_top
        
        mov        ax, 09h
        push        ax                ; attr
        mov        ax, offset msg0
        push        ax                ; str
        mov        ax, 0
        push        ax                ; y
        xor        ax, ax
        push        ax                ; x
        call        PutString
        add        sp, 8
        
        mov        ax, 0Ah
        push        ax                ; attr
        mov        ax, offset msg1
        push        ax                ; str
        mov        ax, 1
        push        ax                ; y
        xor        ax, ax
        push        ax                ; x
        call        PutString
        add        sp, 8
        
        mov        ax, 0Ch
        push        ax                ; attr
        mov        ax, offset msg2
        push        ax                ; str
        mov        ax, 2
        push        ax                ; y
        xor        ax, ax
        push        ax                ; x
        call        PutString
        add        sp, 8
        
        mov        ax, 0Eh
        push        ax                ; attr
        mov        ax, offset msg3
        push        ax                ; str
        mov        ax, 3
        push        ax                ; y
        xor        ax, ax
        push        ax                ; x
        call        PutString
        add        sp, 8
        
        mov        ax, 4c00h
        int        21h
code ends
end start
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-7-7 20:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表