因为学校没教过 , 所以自己找个练练......

       
TITLE SNAKE GAME BY MASM 5.0  CopyRight (C) Detective QQ:87036211

; HLine  画横线函数
; VLine  画竖线函数
; Rec  画无填充矩形
; Bar  画矩形
; SetGb    设置光标位置
; Msg  显示字符串
; Delay  延时
; MsgHz  显示一个64*64汉字
; AddSpeed 增加速度
; SubSpeed 减少速度
; PrtMsg  显示提示
; PrtSpd_Proc     显示初始状态
; HidSpd_Proc 显示移动后的状态
; Random  产生随机数种子
; Rand  产生指定范围大小的随机数
; GameInit 初始化游戏界面以及数据
; SelSpeed 选择游戏速度
; GameProc 游戏过程
; InitSnakeData 初始四节位置
; FoodInit 产生事物位置

;--------------------------------------------------------------------
;等值表

UP EQU 48h
DOWN EQU 50h
LEFT EQU 4Bh
RIGHT EQU 4Dh
QUIT EQU 01h
ENTER EQU 1Ch
;--------------------------------------------------------------------

 .model small
 .stack 300
 .data
;--------------------------------------------------------------------
;蛇的一系列参数


sPosX dw 107

;蛇的生命      
Life db  1
;蛇的方向
Direct db 2 
;速度
Speed db 3
;得分
Score dw 4 dup(0)
;随机数种子
Seed dw 200     
;--------------------------------------------------------------------


;--------------------------------------------------------------------
;显示的一系列字符串
;得分
szScore db 'score'      
;速度选择 
szList  db '1  2  3  4  5  6  7  8  9  '
;作者
szName db 'CopyRight (C) Detective QQ:87036211'    
;--------------------------------------------------------------------


HzSnake db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,010h,000h,000h,000h
 db 000h,000h,000h,000h,00fh,0c0h,000h,000h
 db 000h,000h,000h,000h,007h,0f0h,000h,000h
 db 000h,000h,000h,000h,003h,0fch,000h,000h
 db 000h,000h,0f0h,000h,003h,0fch,000h,000h
 db 000h,000h,0f8h,000h,001h,0feh,000h,000h
 db 000h,000h,0fch,000h,000h,0feh,000h,000h
 db 000h,000h,0bch,000h,000h,07eh,000h,000h
 db 000h,000h,03eh,000h,000h,0feh,000h,000h
 db 000h,000h,01eh,000h,003h,0feh,0f0h,000h
 db 000h,000h,01eh,000h,0ffh,0ffh,0f8h,000h
 db 000h,000h,01eh,001h,0c0h,07fh,0fch,000h
 db 000h,000h,01eh,001h,0e3h,0ffh,01eh,000h
 db 000h,000h,01eh,001h,0efh,0fch,03fh,000h
 db 000h,000h,01fh,081h,0ffh,0f0h,07fh,000h
 db 000h,000h,01fh,0f1h,0ffh,0c1h,0ffh,000h
 db 000h,000h,01fh,0ffh,0ffh,01fh,0ffh,000h
 db 000h,000h,03fh,0ffh,0fch,03fh,0feh,000h
 db 000h,000h,0ffh,0ffh,0f0h,070h,000h,000h
 db 000h,001h,0ffh,07fh,0e0h,070h,000h,000h
 db 000h,083h,0fch,07fh,0c0h,03eh,000h,000h
 db 000h,0ffh,0fch,0ffh,080h,03fh,000h,000h
 db 000h,07fh,03dh,0ffh,080h,07fh,080h,000h
 db 000h,07eh,03fh,0f7h,000h,0ffh,080h,000h
 db 000h,03eh,03fh,0e3h,003h,0ffh,080h,000h
 db 000h,03eh,03fh,0c0h,03fh,0ffh,080h,000h
 db 000h,03eh,03fh,0e0h,0ffh,0ffh,000h,000h
 db 000h,01eh,07fh,0e0h,0ffh,0e0h,000h,000h
 db 000h,01fh,0ffh,0e0h,07fh,080h,000h,000h
 db 000h,01fh,0ffh,0e0h,01fh,000h,000h,000h
 db 000h,01fh,0fch,000h,01fh,000h,000h,000h
 db 000h,01fh,0fdh,080h,03fh,000h,000h,000h
 db 000h,00fh,0ffh,0e0h,03eh,000h,000h,000h
 db 000h,007h,0bfh,0f0h,03eh,000h,000h,000h
 db 000h,000h,03fh,0f8h,07ch,000h,000h,000h
 db 000h,000h,07fh,0fch,07ch,000h,001h,000h
 db 000h,000h,07fh,0feh,07ch,000h,001h,000h
 db 000h,000h,0ffh,0feh,078h,000h,003h,080h
 db 000h,003h,0fch,03eh,0f8h,000h,003h,080h
 db 000h,07fh,0f8h,03eh,0f8h,000h,003h,080h
 db 000h,07fh,0f0h,00ch,0f0h,000h,007h,080h
 db 000h,07fh,0e0h,000h,0f0h,000h,007h,0c0h
 db 000h,03fh,0c0h,000h,0f0h,000h,00fh,0c0h
 db 000h,03fh,080h,000h,078h,000h,03fh,0c0h
 db 000h,01fh,000h,000h,07fh,0ffh,0ffh,0c0h
 db 000h,00eh,000h,000h,07fh,0ffh,0ffh,0c0h
 db 000h,000h,000h,000h,03fh,0ffh,0ffh,0c0h
 db 000h,000h,000h,000h,00fh,0ffh,0ffh,080h
 db 000h,000h,000h,000h,000h,0ffh,0feh,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h
 db 000h,000h,000h,000h,000h,000h,000h,000h


 .data?
;--------------------------------------------------------------------
;这四个变量在显示汉字时要用到
HzColor db ?  ;汉字颜色
HzOldX  dw  ?  ;保存汉字坐标X
HzX  dw  ?  ;汉字坐标X
HzY  dw  ?  ;汉字坐标Y
;--------------------------------------------------------------------


;--------------------------------------------------------------------
;蛇每节的具体坐标 , 可以放200个位置
Pos dw 400 dup(?)
;蛇的长度
Len db ?
;--------------------------------------------------------------------


;--------------------------------------------------------------------
;食物的位置
FoodX dw ?
FoodY dw ?
;--------------------------------------------------------------------


;--------------------------------------------------------------------
;临时变量
eax  dw ?
ebx dw ?
ecx dw ?
edx dw ?
esi  db ?
edi db ?
;--------------------------------------------------------------------
 .code
main proc far
 mov ax , @data
 mov ds , ax
 ;游戏初始化界面
 call GameInit
 ;游戏选择速度
  call SelSpeed
 cmp ax , 1
 je GAMEOVER
 ;游戏过程
 call GameProc
 cmp ax , 1
 je GAMEOVER
GAMEOVER:
 ;设置文本模式
 mov ah , 00
 mov al , 03
 int 10h

 ;退出程序    
 mov ah , 4ch
 int 21h
main endp


;******************************
;函数名: GameProc
;功能:  游戏过程
;传递参数:      空  
;函数返回: ax
;******************************
GameProc proc
 push bx
 push cx
 push dx
 push si
 push di
 mov cl , 0   ;清楚原先屏幕的函数
 mov si , 125
 mov bx , 25
 mov di , 195
 mov dx , 95
 call Bar
 mov cl , 0
 mov si , 1
 mov bx , 125
 mov di , 319
 mov dx , 129
 call Bar
 mov cl , 0
 mov si , 58
 mov bx , 139
 mov di , 267
 mov dx , 156
 call Bar
 ;游戏边框
 ;左右( 2-315 )
 ;上下( 2-160 )
 mov cx , 8
 mov si , 1 
 mov di , 316
 mov bx , 1
 mov dx , 161
 call Rec
 mov dx , 1   ;初始四节位置
 call InitSnakeData
 call PprSpd_Proc   ;显示四节位置
 call FoodInit   ;初始事物位置
M8_1:
  mov ah  , 01h
 int 16h 
 jz M8_2    ;如果没有按键就继续等待按键
 mov ah , 0eh
 mov al , 7
 int 10h 
  mov ah , 00h   ;取得扫描码    
 int 16h  
 cmp ah , LEFT   ;往左移动 
  jz M8_4 
 cmp ah , RIGHT   ;往右边移动 
  jz M8_5
 cmp ah , UP   ;往上移动 
  jz M8_6
 cmp ah , DOWN   ;往下移动 
  jz M8_7
 cmp ah , QUIT   ;结束游戏  
 jz M8_3
 jmp M8_2
M8_4:
 cmp Direct , 2
 je M8_2
 mov Direct , 4
 jmp M8_2
M8_5:
 cmp Direct , 4
 je M8_2
 mov Direct , 2
 jmp M8_2
M8_6:
 cmp Direct , 3
 je M8_2
 mov Direct , 1
 jmp M8_2
M8_7:
 cmp Direct , 1
 je M8_2
 mov Direct , 3
 jmp M8_2
M8_2:
 call HidSpd_Proc
 cmp ax , 1   ;判断是否失败
 jne M8_8
 jmp M8_3
M8_8:
 jmp M8_1 
 
M8_3:
 mov ax , 1
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 ret
GameProc endp

;******************************
;函数名: SelSpeed
;功能:  选择游戏速度
;传递参数:      空  
;函数返回: ax
;******************************
SelSpeed proc
 push bx
 push cx
 push dx
 push si
 push di
 call PprSpd_Proc  ;显示四节位置
M10_1:
  mov ah  , 01h
 int 16h 
 jz M10_2   ;如果没有按键就继续等待按键
 mov ah , 0eh
 mov al , 7
 int 10h 
  mov ah , 00h   ;取得扫描码    
 int 16h  
 cmp ah , LEFT   ;判断扫描码为左 , 游戏速度减1 
  jz M10_3
 cmp ah , RIGHT   ;判断扫描码为右 ,游戏速度加1  
  jz M10_4
 cmp ah , QUIT   ;判断扫描码为ESC , 结束游戏  
 jz M10_5
 cmp ah , ENTER   ;判断扫描码为回车 , 确认开始游戏 
  jz M10_6
 jmp M10_2
M10_3:     ;减少速度
 call SubSpeed
 jmp M10_1
M10_4:     ;增加速度
 call AddSpeed
 jmp M10_1

M10_2:
 call HidSpd_Proc
 jmp M10_1 
M10_5:     ;结束游戏
 mov ax , 1
 jmp M10_7
M10_6:
 mov ax , 0
M10_7:
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 ret
SelSpeed endp

 

;******************************
;函数名: GameInit
;功能:  初始化游戏界面以及数据
;传递参数:      空  
;函数返回: 空
;******************************
GameInit proc
 push ax
 push bx
 push cx
 push dx
 push si
 push di
 mov ah , 00   ;设置图形模式
 mov al , 13h
 int 10h
 call Random   ;随便机数的种子
 mov HzX , 125   ;显示中文字"蛇"字
 mov HzY , 25
 mov HzColor , 4
 mov bx , offset HzSnake
 call MsgHz
 call PrtMsg   ;显示提示      
 ;用四边形作为选择按钮来选择游戏的速度 , 每次移动增加+-24个象素位置
 ;速度1的坐标为( 59 , 140 , 74 , 155 )
 ;速度9的坐标为( 251 , 140 , 266 , 155 )
 mov cl , 50
 mov si , sPosX
 mov bx , 140
 add sPosX , 15
 mov di , sPosX
 sub sPosX , 15
 mov dx , 155
 call Rec
 mov dx , 0   ;初始四节位置
 call InitSnakeData
 mov FoodX , 22
 mov FoodY , 22
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 ret
GameInit endp


;******************************
;函数名: InitSnakeData
;功能:  初始四节位置
;传递参数:     
;  dx 状态标志   
;函数返回: 空
;******************************
InitSnakeData proc
 push ax
 push bx
 push cx
 push dx
 push si
 push di
 mov al , 4
 mov Len , al
 mov bx , offset pos
 mov cx , 4
 mov ax , 17   ;左边坐标赋值  
 cmp dx , 1   ;上边坐标赋值
 je M9_2    ;判断是速度测试期还是正式游戏初始期
 mov dx , 125
 jmp M9_1
M9_2:
 mov dx , 2  
M9_1:
 mov [bx] , ax   ;具体赋值  
 sub ax , 5
 add bx , 2   ;节与节之间间隔为1
 mov [bx] , dx
 add bx , 2  
 loop M9_1
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 ret
InitSnakeData endp

;******************************
;函数名: PrtSpd_Proc
;功能:  显示蛇的初始状态
;传递参数:      空  
;函数返回: 空
;******************************
PprSpd_Proc proc
 push ax
 push bx
 push cx
 push dx
 push si
 push di
 mov bx , offset pos  ;显示初始蛇
 mov cx , 4
M6_1:
 push cx
 mov cl , 80   ;取得左右坐标
 mov si , [bx]
 mov di , si
 add di , 4
 add bx , 2
 push bx    ;取得上下坐标
 push si
 mov si , [bx]
 mov bx , si
 pop si
 mov dx , bx
 add dx , 4
 call Bar
 pop bx
 add bx , 2
 pop cx
 loop M6_1
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 ret
PprSpd_Proc  endp


;******************************
;函数名: HidSpd_Proc
;功能:  显示移动后蛇的具体位置
;传递参数:      空  
;函数返回: ax
;******************************
HidSpd_Proc proc
 push bx
 push cx
 push dx
 push si
 push di 
 mov cl , Speed   ;延时
 call Delay 
 mov bx , offset pos
 mov cl , len   ;移动到最后一节位置
 dec cl
 xor ax , ax
 mov al , cl
 mov cl , 4
 mul cl
        add bx , ax
 push bx
 mov dx , [bx]   ;保存最后一节的位置
 mov eax , dx
 add bx , 2
 mov dx , [bx]
 mov ebx , dx
 pop bx
 push bx    ;擦除最后一节
 mov cl , 0    
 mov si , [bx]
 mov di , si
 add di , 4
 add bx , 2
 push bx   
 push si
 mov si , [bx]
 mov bx , si
 pop si
 mov dx , bx
 add dx , 4
 call Bar
 pop bx
 pop bx 
 mov cl , Len
 dec cx
M7_1:     ;最后一节开始循环取前一节的坐标
 push bx
 sub bx , 4
 mov dx , [bx]
 add bx , 2
 mov si , [bx]
 pop bx
 mov [bx] , dx
 add bx , 2
 mov [bx] , si
 sub bx , 6
 loop M7_1
 mov bx , offset pos  ;重新定义第一节后并显示第一节
 cmp Direct , 1   ;往上的判断 
 je M7_2_1
 jmp M7_NEXT_2
M7_2_1:
 add bx , 2
 mov ax , [bx]
 sub ax , 5
 jnc M7_2_1_1
 mov ax , 157
M7_2_1_1:   
  mov [bx] , ax
 sub bx , 2
 jmp M7_3
M7_NEXT_2:    ;往右的判断   
 cmp Direct , 2  
 je M7_2_2
 jmp M7_NEXT_3
M7_2_2:
 mov ax , [bx]
 add ax , 5  
 cmp ax , 315
 jb M7_2_2_1   
 mov ax , 2
M7_2_2_1:
 mov [bx] , ax
 jmp M7_3
M7_NEXT_3:    ;往下的判断
 cmp Direct , 3   
 je M7_2_3
 jmp M7_NEXT_4
M7_2_3:
 add bx , 2
 mov ax , [bx]
 add ax , 5
 cmp ax , 161
 jb M7_2_3_1
 mov ax , 2
M7_2_3_1:   
  mov [bx] , ax
 sub bx , 2
 jmp M7_3
M7_NEXT_4:    ;往左的判断   
 cmp Direct , 4  
 je M7_2_4
M7_2_4:
 mov ax , [bx]
 sub ax , 5  
 jnc M7_2_4_1   
 mov ax , 312
M7_2_4_1:
 mov [bx] , ax
 jmp M7_3

M7_3:  
 mov cl , 80    
 mov si , [bx]
 mov di , si
 add di , 4
 add bx , 2
 push bx   
 push si
 mov si , [bx]
 mov bx , si
 pop si
 mov dx , bx
 add dx , 4
 call Bar
 pop bx
 mov bx , offset Pos  ;判断是否增加一节
 mov ax , [bx]
 add bx , 2
 mov dx , [bx]
 mov cx , 0
 cmp ax , FoodX
 jne M7_4
 inc cx
M7_4:
 cmp dx , FoodY
 jne M7_5
 inc cx
M7_5: 
 cmp cx , 2
 je M7_6
 jmp M7_7
M7_6:
 inc Len    ;增加一节
 mov bx , offset pos
 mov cl , len   ;移动到最后一节位置
 dec cl
 xor ax , ax
 mov al , cl
 mov cl , 4
 mul cl
        add bx , ax
 mov dx , eax
 mov [bx] , dx
 add bx , 2
 mov dx , ebx
 mov [bx] , dx
 mov si , eax
 mov di , si
 add di , 4
 mov bx , ebx
 mov dx , bx
 add dx , 4
 mov cl , 80
 call Bar 
 call FoodInit   ;产生一节新的食物
M7_7:

 mov ax , 1   ;返回标志 ,0代表无异常
 mov bx , offset pos  ;判断是否碰到自己的身体
 mov si , [bx]
 add bx , 2
 mov di , [bx]
 add bx , 2

 mov cl , len
 dec cx
M7_8:
 push cx
 xor cx , cx
 mov eax , cx   ;计数器 , 累加到2表示失败
 mov dx , [bx]
 add bx , 2
 mov cx , [bx]
 add bx , 2
 cmp si , dx
 jne M7_10
 inc eax
M7_10: 
  cmp di , cx
 jne M7_11
 inc eax
M7_11:
 mov cx , eax
 cmp cx , 2
 je M7_9    ;失败
 pop cx
 loop M7_8
 mov ax , 0
 jmp M7_12
M7_9:
 pop cx
M7_12:
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 ret
HidSpd_Proc endp

;******************************
;函数名: AddSpeed
;功能:  增加游戏速度
;传递参数:      空  
;函数返回: 空
;******************************
AddSpeed proc
 push ax
 push bx
 push cx
 push dx
 push si
 push di
 mov cl , 0
 mov si , sPosX
 mov bx , 140
 add sPosX , 15
 mov di , sPosX
 sub sPosX , 15
 mov dx , 155
 call Rec
 cmp Speed , 9   ;从9移动到1
 jnz M11_1
 mov Speed , 1
 mov sPosX , 59
 jmp M11_2 
M11_1:
 add Speed , 1
 add sPosX , 24
M11_2:
 mov cl , 50
 mov si , sPosX
 mov bx , 140
 add sPosX , 15
 mov di , sPosX
 sub sPosX , 15
 mov dx , 155
 call Rec
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax 
 ret
AddSpeed endp

 

;******************************
;函数名: PrtMsg
;功能:  显示提示
;传递参数:      空  
;函数返回: 空
;******************************
PrtMsg proc
 push ax
 push bx
 push cx
 push dx
 push si
 push di 
 mov dx , 1208h   ;显示1-9速度选择9个数字
        call SetGb 
 lea bp , szList
 mov cx , 27
 call Msg
 mov dx , 1803h   ;显示作者
        call SetGb 
 lea bp , szName
 mov cx , 34
 call Msg
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax 
 ret
PrtMsg endp

;******************************
;函数名: FoodInit
;功能:  产生事物位置
;传递参数:      空  
;函数返回: 空
;******************************
FoodInit proc
 push ax
 push bx
 push cx
 push dx
 push si
 push di
M13_1:
 xor cx , cx
 mov si , 63   ;随机FoodX坐标
 call Rand
 mov bx , 5
 mul bx
 add ax , 2
 mov bx , ax
 cmp ax , FoodX
 je M13_2
 jmp M13_3
M13_2:
 inc cx
M13_3:     ;随机FoodY坐标
 mov si , 32
 call Rand
 mov dx , 5
 mul dx
 add ax , 2
 mov dx , ax
 cmp ax , FoodY
 je M13_4
 jmp M13_5
M13_4:
 inc cx
M13_5:
 cmp cx , 2   ;判断是否需要重新产生随机值
 je M13_1

 mov cl , len   ;判断是否与蛇的某节身体重合
 dec cl
 mov si , offset Pos
 mov eax , bx   ;把新位置保存到临时变量中
 mov FoodX , bx
 mov ebx , dx
 mov FoodY , dx
M13_6:
 xor ax , ax
 mov bx , [si]
 add si , 2
 mov dx , [si]
 add si , 2
 cmp bx , FoodX
 jne M13_7
 inc ax
M13_7:
 cmp dx , FoodY
 jne M13_8
 inc ax
M13_8:
 cmp ax , 2
 je M13_1   ;重复则重新开始随机值
 loop M13_6
M13_9:
 mov bx , eax
 mov dx , ebx
 mov FoodX , bx
 mov FoodY , dx
 mov si , bx   ;显示食物
 mov di , si
 add di , 4
 mov bx , dx
 mov dx , bx
 add dx , 4
 mov cl , 4
 call Bar 
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 ret
FoodInit endp

;******************************
;函数名: SubSpeed
;功能:  减少游戏速度
;传递参数:      空  
;函数返回: 空
;******************************
SubSpeed proc
 push ax
 push bx
 push cx
 push dx
 push si
 push di
 mov cl , 0
 mov si , sPosX
 mov bx , 140
 add sPosX , 15
 mov di , sPosX
 sub sPosX , 15
 mov dx , 155
 call Rec
 cmp Speed , 1   ;从1移动到9
 jnz M12_1
 mov Speed , 9
 mov sPosX , 251
 jmp M12_2 
M12_1:
 sub Speed , 1
 Sub sPosX , 24
M12_2:
 mov cl , 50
 mov si , sPosX
 mov bx , 140
 add sPosX , 15
 mov di , sPosX
 sub sPosX , 15
 mov dx , 155
 call Rec
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 ret
SubSpeed endp

;******************************
;函数名: HLine
;功能:  画横线
;传递参数:      
;  ah 0ch
;  si 起点
;   di 终点
;  al 颜色号
;  dx 行号 
;函数返回: 空
;******************************
HLine proc near
 push ax
 push bx
 push cx
 push dx
 push si
 push di 
 mov bx , 1   ;默认终点大于起点
 push si
 clc
 sub si , di
 jnc M1_1   ;负数
 jmp M1_2    ;正数
M1_1: neg bx
M1_2: pop si
M1_3:     ;循环画线
 mov cx , si
 int 10h
 add si , bx
 cmp si , di
 je M1_4
 jmp M1_3
M1_4:
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 ret
HLine endp


;******************************
;函数名: VLine
;功能:  画竖线
;传递参数:      
;  ah 0ch
;  si 起点
;   di 终点
;  al 颜色号
;  cx 列号 
;函数返回: 空
;******************************
VLine proc near
 push ax
 push bx
 push cx
 push dx
 push si
 push di 
 mov bx , 1   ;默认终点大于起点
 push si
 clc
 sub si , di
 jnc M2_1   ;负数
 jmp M2_2    ;正数
M2_1: neg bx
M2_2: pop si
M2_3:     ;循环画线
 mov dx , si
 int 10h
 add si , bx
 cmp si , di
 je M2_4
 jmp M2_3
M2_4:
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 ret
VLine endp

;******************************
;函数名: Rec
;功能:  画四边形
;传递参数:     
;  cl 颜色
;  si 左边
;  bx 上边
;  di  右边
;  dx 下边
;函数返回: 空
;******************************
Rec proc near
 push ax
 push bx
 push cx
 push dx
 push si
 push di 
 mov ah , 0ch
 mov al , cl
 push dx
 mov dx , bx
 call HLine   ;画上边线
 pop dx
 call HLine   ;画下边线 
 mov cx , si
 mov si , bx
 push di
 mov di , dx
  call VLine   ;画左边线
 pop cx
 inc di    ;补右下角一点
 call VLine   ;画右边线
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 ret
Rec endp

;******************************
;函数名: Bar
;功能:  画填充矩形
;传递参数:     
;  cl 颜色
;  si 左边
;  bx 上边
;  di  右边
;  dx 下边
;函数返回: 空
;******************************
Bar proc near
 push ax
 push bx
 push cx
 push dx
 push si
 push di 
 mov ah , 0ch
 mov al , cl 
M4_1:
 push dx
 mov dx , bx
 call HLine
 pop dx
 inc bx
 cmp bx , dx
 jz M4_2
 jmp M4_1
M4_2:
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 ret 
Bar endp

;******************************
;函数名: Msg
;功能:  输出字符串
;传递参数:     
;  bp  字符串偏移地址
;  cx  字符串长度
;  dh/di  行/列
;函数返回: 空
;******************************
Msg     proc near             
 push ax
 push bx
 push cx
 push dx
 push si
 push di 

        push es  
        push ds
        pop es    ;将数据段ds送es , 相当于 ES : BP
        mov al , 0
        mov ah , 13h
 mov bx , 2
        int 10h
        pop es

 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 ret             
Msg     endp

;******************************
;函数名: SetGb
;功能:  设置光标位置
;传递参数:     
;  dh/dl 行/列
;函数返回: 空
;******************************
SetGb   proc near
 push ax
 push bx
 push cx
 push dx
 push si
 push di 
         
        mov bh , 0
        mov ah , 02h
        int 10h

 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax   
        ret
SetGb   endp

;******************************
;函数名: Delay
;功能:  延时
;传递参数:     
;  cx 延时速度(理论上1为0.5秒)     
;函数返回: 空
;******************************
Delay proc
 push ax
 push cx    
 mov ax , 0ah
 sub ax , cx
 mov cx , ax
M3_1: push cx    ;外层循环来控制延时速度
 mov cx , 3500   ;标准半秒应该是33144大小
M3_2: in al , 61h
 and al , 10h
 cmp al , ah
 je M3_1
 mov ah , al
 loop M3_2
 pop cx
 loop M3_1 
 pop cx
 pop ax
 ret
Delay endp

;******************************
;函数名: MsgHz
;功能:  显示一个64*64汉字
;传递参数:      
;  HzY y位置
;   HzX x位置
;  HzColor 颜色
;  bx      中文偏移地址 
;函数返回: 空
;******************************
MsgHz proc
 push ax
 push bx
 push cx
 push dx
 push si
 push di 
 mov cx , 512
 mov dx , HzX
 mov HzOldX , dx
 mov dx , 0     ;统计字符个数 , 到一定子数换行
M5_1:   
 mov al , [bx]     ;取出一个字符
  push cx
 mov cx , 8
M5_2:
  rcl  al , 1
 jnc  M5_3      ;没有进位
 push ax
 push dx 
 push cx
 mov ah , 0ch     ;写象素
 mov al , HzColor
 mov dx , HzY
 mov cx , HzX
 int 10h
 pop cx
 pop dx
 pop ax
M5_3:    
 inc HzX
 loop M5_2
 pop cx
 inc bx       ;取下一个字符
  inc dx
 cmp dx , 8
 jne M5_4
  mov dx , 0    ;换行
  inc HzY
 push dx
 mov dx , HzOldX
 mov HzX  , dx      ;恢复原来x坐标
 pop dx
M5_4:
 loop M5_1
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 ret
MsgHz endp


;******************************
;函数名: Random
;功能:         随机数种子
;传递参数:      空
;函数返回: 空
;******************************
Random proc
 push ax
 push bx
 push cx
 push dx
 push si
 push di
       sti
       mov ah,0               ;读时钟计数器值
       int 1ah 
 add dx , Seed
 and dx , 8fffh
 mov Seed , dx
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
    ret
Random endp


;******************************
;函数名: Rand
;功能:  产生指定范围大小的随机数
;传递参数:      
;  si 数字的范围最大值+1
;函数返回: ax 返回随机数的值
;******************************
Rand  proc
 push bx
 push cx
 push dx
 push si
 push di
       sti
       mov ah,0               ;读时钟计数器值
       int 1ah
      mov ax , Seed
      add ax , dx
      and ax , 8fffh
      mov Seed , ax
      mov dx , 0
      mov bx , si   ;指定随机数的范围
      div bx   
      mov ax , dx
 pop di
 pop si
 pop dx
 pop cx
 pop bx
       ret
Rand  endp
end main


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,以下是一个简单的 Spring Boot 实战项目,用于管理用户信息: 1. 创建一个基础的 Spring Boot 项目,引入以下依赖: ```xml <!-- Spring Boot Web 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- Spring Boot JPA 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <!-- H2 数据库依赖 --> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> ``` 2. 创建一个实体类 User,包含 id、name、age 三个属性: ```java @Entity @Table(name = "user") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; private Integer age; // 省略 getter 和 setter 方法 } ``` 3. 创建一个 UserRepository 接口,继承 JpaRepository,用于操作用户数据: ```java @Repository public interface UserRepository extends JpaRepository<User, Long> { } ``` 4. 创建一个 UserController 类,用于处理用户信息的增删改查: ```java @RestController @RequestMapping("/users") public class UserController { @Autowired private UserRepository userRepository; @GetMapping("") public List<User> list() { return userRepository.findAll(); } @PostMapping("") public User create(@RequestBody User user) { return userRepository.save(user); } @GetMapping("/{id}") public User get(@PathVariable Long id) { return userRepository.findById(id).orElse(null); } @PutMapping("/{id}") public User update(@PathVariable Long id, @RequestBody User user) { user.setId(id); return userRepository.save(user); } @DeleteMapping("/{id}") public void delete(@PathVariable Long id) { userRepository.deleteById(id); } } ``` 5. 启动项目,访问 http://localhost:8080/users 即可查看用户列表,使用 POST、PUT、DELETE 方法操作用户信息。 以上就是一个简单的 Spring Boot 实战项目,可以通过这个项目练习 Spring Boot 的基本使用和 RESTful API 的实现。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值