项目环境
- 编译环境:搭建一个nasm2.8的编译环境。
- 镜像文件:采用winhex_18.2刷入编码。
- 虚拟机:采用Bochs-2.4.5。
项目软件
- 傻瓜式环境配置。
运行结果
程序源码(.asm)
org 0x8400
jmp start
flag db 0 ;0小写/1大写
start:
;sti
mov ax,0xb800 ;指向文本模式的显示缓冲区
mov es,ax
mov ax,0
mov ds,ax
cli
;mov word [ds:0x20],int_timer0
;mov word [ds:0x22],0
mov word [ds:0x24],int_key ;写入键盘中断9号服务程序地址
mov word [ds:0x26],0
sti
mov si,0 ;打印位置si0
jmp $
;键盘中断
int_key:
mov dx,0x60 ;读取键盘缓冲区数据
in al,dx
;叫切换0/1判断大小写
cmp al , 0x21
je call_change_flag
;叫打印a
cmp al , 0x1E
je call_a
;叫打印b
cmp al , 0x30
je call_b
;叫打印c
cmp al , 0x2E
je call_c
jmp paint
;切换0/1判断大小写
call_change_flag:
call change_flag
jmp paint
;打印a
call_a:
call paint_a
jmp paint
;打印b
call_b:
call paint_b
jmp paint
;打印c
call_c:
call paint_c
jmp paint
;写字母
paint:
mov dx, 0x20
mov al, 0x61
out dx, al
iret
;
paint_a:
push bx
mov bx , [ds:flag] ;判断是否大写
cmp bx , 1
je paint_a_to_A
mov byte [es:si] , 'a'
mov byte [es:si + 1] , 0x0c
inc si
inc si
jmp a_exit
paint_a_to_A:
mov byte [es:si] , 'A'
mov byte [es:si + 1] , 0x0c
inc si
inc si
a_exit:
pop bx
ret
paint_b:
push bx
mov bx , [ds:flag] ;判断是否大写
cmp bx , 1
je paint_b_to_B
mov byte [es:si] , 'b'
mov byte [es:si + 1] , 0x0c
inc si
inc si
jmp b_exit
paint_b_to_B:
mov byte [es:si] , 'B'
mov byte [es:si + 1] , 0x0c
inc si
inc si
b_exit:
pop bx
ret
paint_c:
push bx
mov bx , [ds:flag] ;判断是否大写
cmp bx , 1
je paint_c_to_C
draw_c_c:
mov byte [es:si] , 'c'
mov byte [es:si + 1] , 0x0c
inc si
inc si
jmp c_exit
paint_c_to_C:
mov byte [es:si] , 'C'
mov byte [es:si + 1] , 0x0c
inc si
inc si
c_exit:
pop bx
ret
change_flag:
push bx
mov bx , [ds:flag]
cmp bx , 0
je change_to_1
jmp change_to_0
change_to_0:
mov bx , 0
mov [ds:flag] , bx
jmp flag_exit
change_to_1:
mov bx , 1
mov [ds:flag] , bx
jmp flag_exit
flag_exit: