📄 homework.asm
字号:
;----------------------------------------------------------------------
;Program:homework
;Created by:cipher
;number:2002005042005
;name:Chen Dongxiao
;Finished Date & Time:2004/11/14
;----------------------------------------------------------------------
SSEG SEGMENT PARA STACK 'stack'
dw 100h dup(0) ;Resize the stack by changing the number '100'
SSEG ENDS
DSEG SEGMENT
;TO DO: Add your program's data here
buff db 50 dup(?)
count db 0
grade dw 70,72,80,81,89,56,75,78,34,44,77,88,65,76,87,89,56,34,76,87,98,90,57,83,12,34,66,33,55,67
rank dw 30 dup(?)
Buf db 30
InBuf db 31 dup(?),'$'
start_message db '******************** Start **********************',0ah,0dh,'$'
continue_message db 0ah,0dh,'do you want to continue?(Y/N)$'
result_message db 0ah,0dh,'The result is:$'
string_message db 0ah,0dh,'please enter the string:$'
first_number db 0ah,0dh,'please enter the first number:$'
secend_number db 0ah,0dh,'please enter the secend number:$'
operation_message db 0ah,0dh,'1,mul.2,div.3,add.4,sub. -$'
number_message db 0ah,0dh,'Please enter the number(1-30):$'
grade_message db 0ah,0dh,'The grade is:$'
rank_message db 0ah,0dh,'The rank is:$'
enter_message db 0ah,0dh,'$'
menu_message db 0ah,0dh,'Menu:',0ah,0dh
db '-------------------------------',0ah,0dh
first_menu db '1,the first question.',0ah,0dh
send_menu db '2,the second question.',0ah,0dh
third_menu db '3,the third question.',0ah,0dh
db '-------------------------------',0ah,0dh
warning db 'press q to exit',0ah,0dh
attention db 'have a choice please!! -','$'
line db 0ah,0dh,'-------------------------------',0ah,0dh,'$'
anykey_message db 0ah,0dh,'any key to continue...$'
end_message db 0ah,0dh,0ah,0dh,'********************* End ***********************$'
DSEG ENDS
CSEG SEGMENT
assume cs:CSEG, ds:DSEG, es:DSEG, ss:SSEG
INIT PROC ;Initialize procedure
mov ax, dseg
mov ds, ax
mov es, ax
;TO DO: Add your initialize code here (as your requirement)
ret ;return to the MAIN procedure
INIT ENDP
MAIN PROC ;Here is your program entry point
call INIT ;call the INIT procedure to initialize the program
;**TO DO: Add your main code here**
call menu
mov dx,offset end_message
mov ah,09
int 21h
mov ax, 4c00h ;The end of the program, return to the system
int 21h
MAIN ENDP
;TO DO: Add other procedures(PROC) here (as your requirement)
;display the menu
MENU PROC
call clear
mov dx,offset start_message
mov ah,09
int 21h
mov dx,offset menu_message
mov ah,09
int 21h
mov ah,01
int 21h
cmp al,'1'
jnz secend_sub
call first
secend_sub:cmp al,'2'
jnz third_sub
call secend
third_sub:cmp al,'3'
jnz exit
call third
exit: ret
MENU ENDP
;clear the screan
CLEAR PROC
mov ah,7
mov bh,30h
mov ch,0h
mov cl,0h
mov dh,24h
mov dl,76h
int 10h
cli
mov ah,02h
mov dh,0
mov dl,0
mov bh,0
int 10h
cli
ret
CLEAR ENDP
LINEA PROC
mov dx,offset line
mov ah,09
int 21h
ret
LINEA ENDP
;the first question
FIRST PROC
lea bx,buff
mov count,0
call linea
input1:mov dx,offset string_message
mov ah,09
int 21h
input:mov ah,01
int 21h
mov [bx],al
inc bx
cmp al,'$'
jnz input
lea bx,buff
next:mov cl,[bx]
inc bx
cmp cl,'$'
je disp
cmp cl,30h
jb cont
cmp cl,39h
jbe next
cont:inc count
jmp next
disp:mov dx,offset continue_message
mov ah,09
int 21h
mov ah,01
int 21h
cmp al,'Y'
mov dx,offset enter_message
mov ah,09
int 21h
jz input1
mov dx,offset result_message
mov ah,09
int 21h
mov al,count
MOV AH,0
call DOutput
call linea
mov dx,offset anykey_message
mov ah,09
int 21h
mov ah,01
int 21h
call menu
RET
FIRST ENDP
;the secend question
SECEND PROC
call linea
begin:mov di,0
mov cx,30
loop1:push cx
mov cx,30
mov si,0
mov ax,grade[di]
mov dx,0
loop2:cmp grade[si],ax
jbe go_on
inc dx
go_on:add si,2
loop loop2
inc dx
mov rank[di],dx
add di,2
pop cx
loop loop1
again:mov dx,offset number_message
mov ah,09
int 21h
CALL DInput
sub ax,1
mov bx,2
mul bx
mov si,ax
mov dx,offset grade_message
mov ah,09
int 21h
mov ax,grade[si]
CALL DOutput
mov dx,offset rank_message
mov ah,09
int 21h
mov ax,rank[si]
CALL DOutput
mov dx,offset continue_message
mov ah,09
int 21h
mov ah,01
int 21h
cmp al,'Y'
mov dx,offset enter_message
mov ah,09
int 21h
jz again
call linea
call menu
RET
SECEND ENDP
;the third question
THIRD PROC
call linea
repeat:mov dx,offset first_number
mov ah,09
int 21h
call dinput
mov bx,ax
push bx
mov dx,offset secend_number
mov ah,09
int 21h
call dinput
push ax
call linea
mov dx,offset operation_message
mov ah,09
int 21h
mov ah,01
int 21h
cmp al,'1'
jnz multi
pop ax
pop bx
mul bx
push ax
jmp displayresult
multi:cmp al,'2'
jnz divide
pop bx
pop ax
div bl
and ax,0fh
push ax
jmp displayresult
divide:cmp al,'3'
jnz addtion
pop ax
pop bx
add ax,bx
push ax
jmp displayresult
addtion:cmp al,'4'
jnz goend
pop bx
pop ax
sub ax,bx
push ax
displayresult:mov dx,offset result_message
mov ah,09
int 21h
pop ax
call doutput
goend:mov dx,offset continue_message
mov ah,09
int 21h
mov ah,01
int 21h
cmp al,'Y'
jz repeat
call menu
ret
THIRD ENDP
;binary to string
DOutput PROC
MOV BX,10
MOV DL,' '
PUSH DX
LL1 : MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
CMP AX,0
JA LL1
LL2 : POP DX
MOV AH,2
INT 21H
CMP DL,' '
JNE LL2
RET
DOutput Endp
;string to binary
DInput PROC
MOV AH,0ah
mov dx,offset Buf
INT 21H
mov cl,InBuf[0]
MOV SI,OFFSET InBuf[1]
MOV AX,0
MOV BX,10
againi : MOV DX,0
MUL BX
MOV DL,[SI]
SUB DL,30H
ADD AX,DX
INC SI
LOOP againi
RET
DInput ENDP
CSEG ENDS
;TO DO: Add other segments here (as your requirement)
END MAIN
;----------------------------*The End*--------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -