发现对汇编还是非常的生疏,可能平时程序写少了吧,尤其是对那些寄存器可以间接寻址记的不牢,BIOS调用什么基本是现学现卖。
原来这个BIOS调用比DOS调用还要底层,连输出字符串的功能都没有,输入字符串要要用键盘中断,显示汉字要用字模,所谓字模就是一个点阵,用整数表示,用位运算去判断是否在此处输出点,很傻×的方法。为了能够快速移植(--!)把所有的功能都封装成了函数,在轻松汇编下面能够成功运行。因为很少用汇编写程序,如果程序写得比较菜,还请大家多多指点。
程序以菜单形式实现4个功能:
1.显示自己的英文名字和学号,并要求输入学号,如果匹配,启动windows,否则重新输入,直到正确为止.
2.显示中文名字,其他和1一致。
3.用像素绘一个图
4.用菜单实现所有功能,并实现一个创新功能。
额,这个创新功能实在是没什么想法,就随便输出几句电影的经典台词,就当娱乐一下吧:-P
注意:BIOS不能使用DOS中断,而且所有的数据必须处于代码段中。
PS:老师竟然说我的程序是抄袭的,给了个三分。。。。无语。。。。
;//Bios
;//2010.8.27.
;//coded by abilitytao
.MODEL TINY,C
.386P
.DATA
.CODE
.STACK
;/**///////////////The code following can not be modified////////////////////////
START:
DB 0100H DUP(00H)
ORG 0000H
DB 55H,0AAH
DB 40H
JMP MAIN_ENTRY
ORG 0018H
DB 1CH,00H,00H,00H
DB 50H,43H,49H,52H
DW 4348H,5031H,0000H,0018H,0000H,0180H,0040H,0000H
DW 8000H,0000H,0000H,0FFFFH,0000H,0003H
ORG 0100H
MAIN_ENTRY:
NOP
PUSH DX
PUSH BX
PUSH AX
CALL SHOW_MAIN ;THIS FUNCTION IS WHAT WE WANT
XOR AX,AX
INT 16H
JMP MAIN_EXIT
MAIN_EXIT:
POP AX
POP BX
POP DX
RETF
;/**////////////////////////////////////////////////////////////////////////////
DATASEGMENT PROC NEAR
;//main order
WELCOME DB 'Welcome To My Programme!',0DH,0AH
OP1 DB '1.Simple',0DH,0AH
OP2 DB '2.Normal',0DH,0AH
OP3 DB '3.Good',0DH,0AH
OP4 DB '4.Excellent',0DH,0AH
RE DW '??'
CNT DB '?'
TEM DB '?'
;/**//////////////////////////////////////////////////////////////// STR_NAME DB 'WeiTao Luo'
STR_ID DB 'ID:0706230226',0DH,0AH
STR1 DB '0706230226',00H
STR2 DB '????????????????????'
ERROR DB 'Your input is invalid,plase input your id again,please press anykey to continue',0DH,0AH
RIGHT DB 'Your input is valid,please press anykey to boot the windows',0DH,0AH
CH1 DB 00H,04H,7FH,0FEH,44H,44H,44H,44H,44H,44H,7FH,0FCH,42H,04H,02H,00H,07H,0F0H,08H,10H,14H,20H,62H,0C0H,01H,00H,06H,00H,18H,00H,0E0H,00H
CH2 DB 08H,40H,08H,40H,08H,44H,17H,0FEH,10H,40H,30H,48H,57H,0FCH,90H,40H,10H,44H,1FH,0FEH,10H,44H,10H,44H,10H,54H,10H,48H,10H,40H,10H,40H
CH3 DB 00H,80H,40H,88H,37H,0FCH,10H,80H,83H,0F8H,60H,80H,2FH,0FEH,09H,08H,11H,08H,23H,0FEH,0E2H,08H,25H,08H,28H,88H,30H,88H,20H,28H,20H,10H
RET
;/**///////////////////////////////////////////////////////////////;Forrest Gump
STARTWORD DB 'Forrest Gump !',0DH,0AH
WORD1 DB '1.Life was like a box of chocolates, you never know what you’re gonna get.',0DH,0AH
WORD2 DB '2.Stupid is as stupid does',0DH,0AH
WORD3 DB '3.It made me look like a duck in water',0DH,0AH
WORD4 DB '4.Jenny and I was like peas and carrots.',0DH,0AH
WORD5 DB '5.You just stay away from me please.',0DH,0AH
DATASEGMENT ENDP
;//SHOW NAME `
SHOW_NAME PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV AX,CS
MOV ES,AX
MOV AL,01H
MOV BH,0
MOV BL,74H
MOV CH,0
MOV CL,10 ;lenth
MOV DH,0
MOV DL,0
MOV BP,OFFSET STR_NAME
MOV AH,13H
INT 10H
POP DX
POP CX
POP BX
POP AX
RET
SHOW_NAME ENDP
;/**///////////////////////////////////////////////////////////////////////////////////////////////
;//SHOW STUDENT ID `
SHOW_ID PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV AX,CS
MOV ES,AX
MOV AL,01H
MOV BH,0
MOV BL,74H
MOV CH,0
MOV CL,15 ;
MOV DH,1
MOV DL,0
MOV BP,OFFSET STR_ID
MOV AH,13H
INT 10H
POP DX
POP CX
POP BX
POP AX
RET
SHOW_ID ENDP
;/**///////////////////////////////////////////////////////////////////////////////////////////////////
;SHOW FOR DEBUG
;****************************************************************************************************** `
SHOW_DEBUG PROC NEAR
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV AX,CS
MOV ES,AX
MOV AL,01H
MOV BH,0
MOV BL,74H
MOV CH,0
MOV CL,10 ;
MOV DH,10
MOV DL,10
MOV BP,OFFSET ERROR
MOV AH,13H
INT 10H
POP DX
POP CX
POP BX
POP AX
SHOW_DEBUG ENDP
;/**///////////////////////////////////////////////////////////////////////////////////////////////;******************************************************************************************************
;input your id
INPUT_STR2 PROC NEAR
PUSH DI
PUSH AX
MOV DI ,OFFSET STR2
NEXT:
MOV AH,0
INT 16H
CMP AL,13
JZ ENDPOINT
MOV AH,14
INT 10H
MOV [DI],AL
INC DI
JMP NEXT
ENDPOINT:
MOV AL,0
MOV [DI],AL
MOV AH,14
MOV AL,0AH
INT 10H
MOV AL,0DH
INT 10H
POP AX
POP DI
RET
INPUT_STR2 ENDP
;/**//////////////////////////////////////////////////////////////////////////////////////////////////
;output one string after the cursor,this is the most important use just like the cout.
SHOW_STRING PROC NEAR ;CX:lenth CS:[si] ,the lenth include enter character
PUSH AX
AGAIN:
MOV AH,14
MOV AL,[SI]
INT 10H
INC SI
LOOP AGAIN
POP AX
RET
SHOW_STRING ENDP
;/**/////////////////////////////////////////////////////////////////////////////////////////////
;//Cmp STR1 and STR2 which end with 0,if they are the same ,ZF = 0,else ZF = 1
CMP_STR1AND2 PROC NEAR
PUSH ES
PUSH AX
PUSH BX
PUSH DI
PUSH SI
MOV AX,CS
MOV ES,AX
MOV SI,OFFSET STR1
MOV DI,OFFSET STR2
AGAIN2:
CMPSB
JNZ NOTTHESAME
LOOP AGAIN2
JMP ISTHESAME ;
NOTTHESAME:
PUSHF
POP AX
MOV BX,0FFBFH
AND AX,BX
PUSH AX
POPF
JMP DONE
ISTHESAME:
PUSHF
POP AX
MOV BX,0FFFFH
AND AX,BX
PUSH AX
POPF
DONE:
POP SI
POP DI
POP BX
POP AX
POP ES
RET
CMP_STR1AND2 ENDP
;/**/////////////////////////////////////////////////////////////////////////////////////////////////
;CLR THE SCREEN
CLR PROC NEAR
PUSH AX
MOV AX,03H
INT 10H
POP AX
RET
CLR ENDP
;/**////////////////////////////////////////////////////////////////////////////////////////
CLR2 PROC NEAR
PUSHA
PUSH DX
PUSH BX
MOV AL,0
MOV AH,06H
MOV BH,07H
MOV CH,0
MOV CL,0
MOV DH, 100
MOV DL,100
INT 10H
POP BX
POP DX
POPA
RET
CLR2 ENDP
START_MENU PROC NEAR
PUSH CX
PUSH SI
MOV CX,26
MOV SI,OFFSET WELCOME
CALL SHOW_STRING
MOV CX,10
MOV SI,OFFSET OP1
CALL SHOW_STRING
MOV CX,10
MOV SI,OFFSET OP2
CALL SHOW_STRING
MOV CX,8
MOV SI,OFFSET OP3
CALL SHOW_STRING
MOV CX,13
MOV SI,OFFSET OP4
CALL SHOW_STRING
POP SI
POP CX
RET
START_MENU ENDP
OUTPUTCHINESENAME PROC NEAR ;interface DX: row ,CX Col,cs:[si] POINT THE HEAD OF THE ARRAY
PUSH ES
PUSH AX
PUSH BX
PUSH DI
PUSH BP
MOV AL,7
MOV BH,1
MOV AH,0CH
MOV CNT,16
MOV RE ,CX
L1:
PUSH BX
MOV BX,[SI]
MOV TEM,BH
MOV BH,BL
MOV BL,TEM
MOV [SI],BX
POP BX
MOV CX,RE
MOV DI,0001H
L2:
ROR DI,1
TEST [SI],DI
JZ L2END
INT 10H
L2END:
INC CX
CMP DI,0001H
JZ L1END
JMP L2
L1END:
INC SI
INC SI
INC DX
DEC CNT
CMP CNT,0
JZ THEEND
JMP L1
THEEND:
POP BP
POP DI
POP BX
POP AX
POP ES
RET
OUTPUTCHINESENAME ENDP
PICTURE PROC NEAR
PUSHA
PUSH ES
PUSH DS
MOV AX,CS
MOV ES,AX
MOV AX,0013H
INT 10H
MOV AL,7
MOV BH,1
MOV AH,0CH
MOV CX,1
MOV DX,19
INT 10H
MOV DX,20
INT 10H
MOV DX,21
INT 10H
MOV DX,22
INT 10H
MOV DX,23
INT 10H
MOV DX,24
INT 10H
MOV CX,2
MOV DX,18
INT 10H
MOV DX,15
INT 10H
MOV DX,16
INT 10H
MOV DX,17
INT 10H
MOV DX,28
INT 10H
MOV DX,25
INT 10H
MOV DX,26
INT 10H
MOV DX,27
INT 10H
MOV CX,3
MOV DX,13
INT 10H
MOV DX,12
INT 10H
MOV DX,14
INT 10H
MOV DX,31
INT 10H
MOV DX,29
INT 10H
MOV DX,30
INT 10H
MOV CX,4
MOV DX,11
INT 10H
MOV DX,32
INT 10H
MOV CX,5
MOV DX,9
INT 10H
MOV DX,10
INT 10H
MOV DX,34
INT 10H
MOV DX,33
MOV CX,6
MOV DX,35
INT 10H
MOV DX,8
INT 10H
MOV CX,7
MOV DX,7
INT 10H
MOV DX,36
INT 10H
MOV CX,8
MOV DX,6
INT 10H
MOV DX,37
INT 10H
MOV CX,9
MOV DX,5
INT 10H
MOV DX,38
INT 10H
MOV CX,10
MOV DX,4
INT 10H
MOV DX,39
INT 10H
MOV CX,11
MOV DX,4
INT 10H
MOV DX,39
INT 10H
MOV DX,10
INT 10H
MOV DX,11
INT 10H
MOV DX,12
INT 10H
MOV CX,12
MOV DX,3
INT 10H
MOV DX,40
INT 10H
MOV DX,8
INT 10H
MOV DX,9
INT 10H
MOV DX,10
INT 10H
MOV DX,14
INT 10H
MOV CX,13
MOV DX,3
INT 10H
MOV DX,40
INT 10H
MOV DX,6
INT 10H
MOV DX,7
INT 10H
MOV DX,15
INT 10H
MOV DX,16
INT 10H
MOV CX,14
MOV DX,2
INT 10H
MOV DX,41
INT 10H
MOV DX,5
INT 10H
MOV DX,17
INT 10H
MOV DX,18
INT 10H
MOV CX,15
MOV DX,2
INT 10H
MOV DX,41
INT 10H
MOV DX,4
INT 10H
MOV DX,19
INT 10H
MOV CX,16
MOV DX,2
INT 10H
MOV DX,3
INT 10H
MOV DX,20
INT 10H
MOV DX,41
INT 10H
MOV CX,17
MOV DX,2
INT 10H
MOV DX,20
INT 10H
MOV DX,41
INT 10H
MOV CX,18
MOV DX,1
INT 10H
MOV DX,42
INT 10H
MOV DX,11
INT 10H
MOV DX,20
INT 10H
MOV DX,32
INT 10H
MOV CX,19
MOV DX,1
INT 10H
MOV DX,42
INT 10H
MOV DX,10
INT 10H
MOV DX,12
INT 10H
MOV DX,31
INT 10H
MOV DX,33
INT 10H
MOV DX,21
INT 10H
MOV CX,20
MOV DX,1
INT 10H
MOV DX,42
INT 10H
MOV DX,9
INT 10H
MOV DX,13
INT 10H
MOV DX,30
INT 10H
MOV DX,34
INT 10H
MOV DX,21
INT 10H
MOV CX,21
MOV DX,1
INT 10H
MOV DX,42
INT 10H
MOV DX,8
INT 10H
MOV DX,14
INT 10H
MOV DX,29
INT 10H
MOV DX,35
INT 10H
MOV DX,21
INT 10H
MOV CX,42
MOV DX,19
INT 10H
MOV DX,20
INT 10H
MOV DX,21
INT 10H
MOV DX,22
INT 10H
MOV DX,23
INT 10H
MOV DX,24
INT 10H
MOV CX,41
MOV DX,18
INT 10H
MOV DX,15
INT 10H
MOV DX,16
INT 10H
MOV DX,17
INT 10H
MOV DX,28
INT 10H
MOV DX,25
INT 10H
MOV DX,26
INT 10H
MOV DX,27
INT 10H
MOV CX,40
MOV DX,13
INT 10H
MOV DX,12
INT 10H
MOV DX,14
INT 10H
MOV DX,31
INT 10H
MOV DX,29
INT 10H
MOV DX,30
INT 10H
MOV CX,39
MOV DX,11
INT 10H
MOV DX,32
INT 10H
MOV CX,38
MOV DX,9
INT 10H
MOV DX,10
INT 10H
MOV DX,34
INT 10H
MOV DX,33
MOV CX,37
MOV DX,35
INT 10H
MOV DX,8
INT 10H
MOV CX,36
MOV DX,7
INT 10H
MOV DX,36
INT 10H
MOV CX,35
MOV DX,6
INT 10H
MOV DX,37
INT 10H
MOV CX,34
MOV DX,5
INT 10H
MOV DX,38
INT 10H
MOV CX,33
MOV DX,4
INT 10H
MOV DX,39
INT 10H
MOV DX,31
INT 10H
MOV DX,32
INT 10H
MOV DX,33
INT 10H
MOV CX,32
MOV DX,4
INT 10H
MOV DX,39
INT 10H
MOV DX,29
INT 10H
MOV DX,30
INT 10H
MOV DX,34
INT 10H
MOV DX,35
INT 10H
MOV CX,31
MOV DX,3
INT 10H
MOV DX,40
INT 10H
MOV DX,27
INT 10H
MOV DX,28
INT 10H
MOV DX,35
INT 10H
MOV CX,30
MOV DX,3
INT 10H
MOV DX,40
INT 10H
MOV DX,26
INT 10H
MOV DX,37
INT 10H
MOV CX,29
MOV DX,2
INT 10H
MOV DX,41
INT 10H
MOV DX,24
INT 10H
MOV DX,25
INT 10H
MOV DX,38
INT 10H
MOV CX,28
MOV DX,2
INT 10H
MOV DX,41
INT 10H
MOV DX,23
INT 10H
MOV DX,39
INT 10H
MOV CX,27
MOV DX,2
INT 10H
MOV DX,40
INT 10H
MOV DX,22
INT 10H
MOV DX,41
INT 10H
MOV CX,26
MOV DX,2
INT 10H
MOV DX,22
INT 10H
MOV DX,41
INT 10H
MOV CX,25
MOV DX,1
INT 10H
MOV DX,42
INT 10H
MOV DX,11
INT 10H
MOV DX,22
INT 10H
MOV DX,32
INT 10H
MOV CX,24
MOV DX,1
INT 10H
MOV DX,42
INT 10H
MOV DX,10
INT 10H
MOV DX,12
INT 10H
MOV DX,31
INT 10H
MOV DX,33
INT 10H
MOV DX,22
INT 10H
MOV CX,23
MOV DX,1
INT 10H
MOV DX,42
INT 10H
MOV DX,9
INT 10H
MOV DX,13
INT 10H
MOV DX,30
INT 10H
MOV DX,34
INT 10H
MOV DX,21
INT 10H
MOV CX,22
MOV DX,1
INT 10H
MOV DX,42
INT 10H
MOV DX,8
INT 10H
MOV DX,14
INT 10H
MOV DX,29
INT 10H
MOV DX,35
INT 10H
MOV DX,21
INT 10H
MOV AH,0
INT 16H
MOV AX,0003H
INT 10H
POP DS
POP ES
POPA
RET
PICTURE ENDP
;//Main Function
SHOW_MAIN PROC NEAR
MOV AX,CS
MOV DS,AX
MOV AX,CS
MOV ES,AX
CALL START_MENU
MOV AH,0
INT 16H
CMP AL,31H
JZ OPTION1
CMP AL,32H
JZ OPTION2
CMP AL,33H
JZ OPTION3
CMP AL,34H
JZ OPTION4
;/this is for OPTION1
;/**//////////////////////////////////////////////////////////////////////////////// OPTION1:
CALL CLR
CALL SHOW_NAME ;output your english name
CALL SHOW_ID ;out put your student id
MOV CX,10 ;
CALL INPUT_STR2 ;input your id
CALL CMP_STR1AND2
JZ CORRECT
WORNG:
MOV CX,81
MOV SI,OFFSET ERROR
CALL SHOW_STRING
MOV AH,0
INT 16H
JMP OPTION1
CORRECT:
MOV CX,61
MOV SI,OFFSET RIGHT
CALL SHOW_STRING
; MOV AH,0
; INT 16H
JMP FINALEND
;/**/////////////////////////////////////////////////////////////////////////////////////
OPTION2:
CALL CLR
MOV AX,0013H
INT 10H
MOV CX,0
MOV DX,0
MOV SI,OFFSET CH1
CALL OUTPUTCHINESENAME
MOV CX,16
MOV DX,0
MOV SI,OFFSET CH2
CALL OUTPUTCHINESENAME
MOV CX,32
MOV DX,0
MOV SI,OFFSET CH3
CALL OUTPUTCHINESENAME
MOV AH,0H ;
INT 16H
JMP OPTION1
JMP FINALEND
OPTION3:
CALL PICTURE
MOV AH,0H
INT 16H
JMP FINALEND
OPTION4:
CALL CLR
MOV SI,OFFSET STARTWORD
MOV CX,16
CALL SHOW_STRING
MOV AL ,0AH
MOV AH,14
INT 10H
MOV AL ,0DH
MOV AH,14
INT 10H
MOV SI,OFFSET WORD1
MOV CX,77
CALL SHOW_STRING
MOV SI,OFFSET WORD2
MOV CX,38
CALL SHOW_STRING
MOV SI,OFFSET WORD3
MOV CX,40
CALL SHOW_STRING
MOV SI,OFFSET WORD4
MOV CX,42
CALL SHOW_STRING
MOV SI,OFFSET WORD5
MOV CX,38
CALL SHOW_STRING
FINALEND:
RET
SHOW_MAIN ENDP
END START