小白求助
第一个题目:计算从1到20的累加和,以十进制的方式显示在屏幕上第二个题目:在80*25的屏幕上,以多种颜色显示多种字符
求大佬这两道题怎么写?
还有DOSBox 0.74怎么在屏幕上显示程序运行结果? 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, ; y
mov al, 160
mul dl
mov di, ax
mov dl, ; x
mov al, 2
mul dl
add di, ax
mov al, ; ch
mov ah, ; attr
mov es:, ax
mov bh, 0 ; 显示页码
mov dh, ; y
mov dl, ; 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, ; x
mov di, ; y
mov bx, ; str
@@:
cmp byte ptr , 0
je @F
push ; attr
xor ah, ah
mov al,
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, ; buffer
mov ax, ; 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 , dl
inc di
xor dx, dx
cmp ax, 0
jne @B
mov byte ptr , 0 ; '\0'
; 下面翻转字符串
dec di
mov si, ; buffer
@@:
cmp si, di
jge @F
mov ah,
mov al,
mov , al
mov , 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
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, ; y
mov al, 160
mul dl
mov di, ax
mov dl, ; x
mov al, 2
mul dl
add di, ax
mov al, ; ch
mov ah, ; attr
mov es:, ax
mov bh, 0 ; 显示页码
mov dh, ; y
mov dl, ; 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, ; x
mov di, ; y
mov bx, ; str
@@:
cmp byte ptr , 0
je @F
push ; attr
xor ah, ah
mov al,
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
页:
[1]