|
发表于 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
复制代码 |
|