如何跳转到用户选择的上一个函数,在行中返回菜单函数,当用户按下1时,它将基于用户之前的选择并跳转到函数
.model small
.stack 100h
.data
message db , 'Please enter your password to login:$'
passcheck db 'Words that you have enter >$'
password db 'jeremy'
count dw 6
correct db 'You have login Successfully !$'
Incorrect db 10,13, 'Invalid password ! Please retype your password again : $'
linefeed db 13, 10, "$"
char db 'n$'
H1 db 10,13,10,13,'PRODUCTS $'
H2 db 10,13,'1. Apple Watch Series 6 $'
H3 db 10,13,'2. IPhone 12 Pro Max $'
H4 db 10,13,'3. Airpod Pro $'
H5 db 10,13,'4. Mac Book Pro 2021 $'
H6 db 10,13,'5. IPad Pro $'
H7 db 10,13,'6. IMac 2021 $'
H8 db 10,13,10,13,'Please Enter The Product That You Interested >$'
;line
H10 db 10,13,'---------------------------------------------$'
;applewatch
H9 db 10,13,' Apple Watch Series 6 USD $'
H11 db 10,13,' 1.Price 449/- $'
H12 db 10,13,' 2.Case Size 40mm 19/- $'
H13 db 10,13,' 3.Case Size 44mm 19/- $'
H14 db 10,13,' 4.GPS 10/- $'
H15 db 10,13,' 5.GPS+Cellular 20/- $'
H16 db 10,13,' 6.Apple Care 79/- $'
H17 db 10,13,'--------------------------------------------- $'
H18 db 10,13,10,13,'Enter the number >$'
;iphone
H19 DB 10,13,' Iphone 12 Pro Max USD $'
H20 DB 10,13,' 1.Price 1099/- $'
H21 DB 10,13,' 2.Graphite 0/- $'
H22 DB 10,13,' 3.Silver 0/- $'
H23 DB 10,13,' 4.Gold 0/- $'
H24 DB 10,13,' 5.Pacific Blue 0/- $'
H25 DB 10,13,' 6.Capacity 128GB 0/- $'
H26 DB 10,13,' 7.Capacity 256GB 100/- $'
H27 DB 10,13,' 8.Capacity 512GB 300/- $'
H28 DB 10,13,' 9.Apple Care 149/- $'
;airpod 2
H29 DB 10,13,' Airpod Pro USD $'
H30 DB 10,13,' 1.Price 249/- $'
H31 DB 10,13,' 2.Apple Care 29/- $'
H32 DB 10,13,' 3.Add Engraving 00/- $'
H33 DB 10,13,' 4.Add GiftWrap And Card 40/- $'
H34 DB 10,13,' 5.Lumen Series lm Case 35/- $'
;Macbook
H35 DB 10,13,' Mac Book Pro 2021 USD $'
H36 DB 10,13,' 1.Price 2799/- $'
H37 DB 10,13,' 2.Space Grey 0/- $'
H38 DB 10,13,' 3.Silver 0/- $'
H39 DB 10,13,' 4.2.3 GHz, Intel 1-9 200/- $'
H40 DB 10,13,' 5.32 GB DDR4 memory 400/- $'
H41 DB 10,13,' 6.64 GB DDR4 memory 800/- $'
H42 DB 10,13,' 7.AMD Radeon Pro 8GB(GDDR6) 100/- $'
H43 DB 10,13,' 8.AMD Radeon Pro 8GB(HBM2) 700/- $'
H44 DB 10,13,' 9.2TB SSD Storage 400/- $'
H45 DB 10,13,' 10.4TB SSD Storage 1000/- $'
H46 DB 10,13,' 11.8TB SSD Storage 2200/- $'
H47 DB 10,13,' 12.Final Cut Pro 300/- $'
H48 DB 10,13,' 13.Logic Pro 200/- $'
;Ipad
H49 DB 10,13,' IPad Pro USD $'
H50 DB 10,13,' 1.Price 1099/- $'
H51 DB 10,13,' 2.Space Grey 0/- $'
H52 DB 10,13,' 3.Storage 256 GB 100/- $'
H53 DB 10,13,' 4.Storage 512 GB 300/- $'
H54 DB 10,13,' 5.Storage 1TB 700/- $'
H55 DB 10,13,' 6.Storage 2TB 1100/- $'
H56 DB 10,13,' 7.WIFI + Cellular 200/- $'
H57 DB 10,13,' 8.Add Keyboard 199/- $'
H58 DB 10,13,' 9.Add Apple Pencil 129/- $'
;IMac 2021
H59 DB 10,13,' IMac 2021 USD $'
H60 DB 10,13,' 1.Price 1699/- $'
H61 DB 10,13,' 2.Memory 16GB 200/- $'
H62 DB 10,13,' 3.Storage 1TB 200/- $'
H63 DB 10,13,' 4.Storage 2TB 600/- $'
H64 DB 10,13,' 5.Magic Trackpad 50/- $'
H65 DB 10,13,' 6.Magic mouse + Magic Trackpad 129/- $'
H66 DB 10,13,' 7.Final Cut Pro 300/- $'
H67 DB 10,13,' 8.Logic Pro 200/- $'
;prompt user
H68 DB 10,13,10,13,10,13,'Do you still want to add on ?$'
H69 DB 10,13,'1.To Customize more $'
H71 DB 10,13,'2.To return to menu $'
H72 DB 10,13,'3.To exit $'
H73 DB 10,13,10,13,'Enter your choice here > $'
H74 DB 10,13,10,13,'Total Price > $'
;Thank You
H75 DB 10,13,'Thank You For Choosing Apple $'
H76 DB 10,13,' ** ** $'
H77 DB 10,13,' ** ** $'
H78 DB 10,13,' ** ** $'
H79 DB 10,13,' ** $'
H80 DB 10,13,' * * * * $'
H81 DB 10,13,' * * $'
H82 DB 10,13,' * * $'
H83 DB 10,13,' * * $'
H84 DB 10,13,' * * $'
H85 DB 10,13,' * * $'
H86 DB 10,13,' * * $'
H87 DB 10,13,' * * $'
H88 DB 10,13,' * * * * $'
value dw ?
total dw ?
;Apple watch
Apple_watch dw 449
Case_40mm dw 19 ;duplicate to 16 bit
Gps dw 10
Gps_cellular dw 20
AppleCare dw 79
;Iphone pro max
Iphonepm dw 1099
capacity1 dw 100
capacity2 dw 300
free dw 0
AppleCare2 dw 149
;Airpod 2
Airpod2 dw 249
AppleCare3 dw 29
GiftWrap dw 40
LumenCase dw 35
;Macbook 2021
Macbook2021 dw 2799
Core dw 200
memory1 dw 400
memory2 dw 800
GraphicCard1 dw 100
GraphicCard2 dw 700
Storage1 dw 400
Storage2 dw 1000
Storage3 dw 2200
FinalC dw 300
LogicP dw 200
;Ipad
Ipad2021 dw 1099
Storage4 dw 100
Storage5 dw 300
Storage6 dw 700
Storage7 dw 1100
Wificell dw 200
keyboard dw 199
Applepen dw 129
;Imac
Imac2021 dw 1699
memory3 dw 200
Storage8 dw 200
Storage9 dw 600
MagicTra dw 50
MagicTramou dw 200
string db 5
DISPLAY MACRO H
MOV AH,9
LEA DX,H
INT 21H
ENDM
.code
begin:
mov ax, @data
mov ds,ax
mov cx, count
mov bx, offset password
;display message
lea dx, message
mov ah, 09
int 21h
again: ; read a character in al without echo
mov ah,08
int 21h
cmp al,[bx]
jne error
inc bx
loop again
mov dx,offset linefeed
mov ah, 09
int 21h
mov dx, offset correct
mov ah,09h
int 21h
call product
error:
mov dx, offset Incorrect
mov ah,09h
int 21h
jmp begin
product:
DISPLAY H1
DISPLAY H2
DISPLAY H3
DISPLAY H4
DISPLAY H5
DISPLAY H6
DISPLAY H7
mov dx, offset H8
mov ah, 09h
int 21h
mov ah,1
int 21h
mov bh,al
sub bh,48
cmp bh,1
je Applewatch
cmp bh,2
je Iphone
cmp bh,3
je Airpod
cmp bh,4
je Macbook
cmp bh,5
je Ipad
cmp bh,6
je Imac
Applewatch:
DISPLAY H9
DISPLAY H10
DISPLAY H11
DISPLAY H12
DISPLAY H13
DISPLAY H14
DISPLAY H15
DISPLAY H16
DISPLAY H17
mov dx, offset H18
mov ah, 09h
int 21h
mov ah,1
int 21h
mov bh,al
sub bh,48
cmp bh,1
je p449
cmp bh,2
je p19
cmp bh,3
je p19
cmp bh,4
je p10
cmp bh,5
je p20
cmp bh,6
je p79
p449:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Apple_watch
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p19:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Case_40mm
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p10:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Gps
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p20:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Gps_cellular
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p79:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, AppleCare
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
;IPHONE
Iphone:
DISPLAY H19
DISPLAY H10
DISPLAY H20
DISPLAY H21
DISPLAY H22
DISPLAY H23
DISPLAY H24
DISPLAY H25
DISPLAY H26
DISPLAY H10
mov dx, offset H18
mov ah, 09h
int 21h
mov ah,1
int 21h
mov bh,al
sub bh,48
cmp bh,1
je p1099
cmp bh,2
je p0
cmp bh,3
je p0
cmp bh,4
je p0
cmp bh,5
je p0
cmp bh,6
je p0
cmp bh,7
je p100
cmp bh,8
je p300
cmp bh,9
je p149
p1099:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Iphonepm
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p0:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, free
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p100:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, capacity1
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p300:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, capacity2
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p149:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, AppleCare2
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
;airpod 2
Airpod:
DISPLAY H29;
DISPLAY H10;
DISPLAY H30;
DISPLAY H31;
DISPLAY H32;
DISPLAY H33;
DISPLAY H34;
DISPLAY H10;
mov dx, offset H18
mov ah, 09h
int 21h
mov ah,1
int 21h
mov bh,al
sub bh,48
cmp bh,1
je p249
cmp bh,2
je p29
cmp bh,3
je p0
cmp bh,4
je p40
cmp bh,5
je p35
p249:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Airpod2
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p29:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, AppleCare3
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p40:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, GiftWrap
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p35:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, LumenCase
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
;Macbook
Macbook:
DISPLAY H35;
DISPLAY H10;
DISPLAY H36;
DISPLAY H37;
DISPLAY H38;
DISPLAY H39;
DISPLAY H40;
DISPLAY H41;
DISPLAY H42;
DISPLAY H43;
DISPLAY H44;
DISPLAY H45;
DISPLAY H46;
DISPLAY H47;
DISPLAY H48;
DISPLAY H10;
mov dx, offset H18
mov ah, 09h
int 21h
mov ah,1
int 21h
mov bh,al
sub bh,48
cmp bh,1
je p2799
cmp bh,2
je p0
cmp bh,3
je p0
cmp bh,4
je p200
cmp bh,5
je p400
cmp bh,6
je p800
cmp bh,7
je p100
cmp bh,8
je p700
cmp bh,9
je p400
cmp bh,10
je p1000
cmp bh,11
je p2200
cmp bh,12
je p300
cmp bh,13
je p200
p2799:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Macbook2021
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p200:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Core
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p400:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, memory1
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p800:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, memory2
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p700:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, GraphicCard2
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p1000:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Storage2
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p2200:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Storage3
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
;Ipad
Ipad:
DISPLAY H49;
DISPLAY H10;
DISPLAY H50;
DISPLAY H51;
DISPLAY H52;
DISPLAY H53;
DISPLAY H54;
DISPLAY H55;
DISPLAY H56;
DISPLAY H57;
DISPLAY H58;
DISPLAY H10;
mov dx, offset H18
mov ah, 09h
int 21h
mov ah,1
int 21h
mov bh,al
sub bh,48
cmp bh,1
je p1099
cmp bh,2
je p0
cmp bh,3
je p100
cmp bh,4
je p300
cmp bh,5
je p700
cmp bh,6
je p1100
cmp bh,7
je p200
cmp bh,8
je p199
cmp bh,9
je p129
p1100:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Storage7
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p199:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, keyboard
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p129:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Applepen
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
;Imac 2021
Imac:
DISPLAY H59;
DISPLAY H10;
DISPLAY H60;
DISPLAY H61;
DISPLAY H62;
DISPLAY H63;
DISPLAY H64;
DISPLAY H65;
DISPLAY H66;
DISPLAY H67;
DISPLAY H10;
mov dx, offset H18
mov ah, 09h
int 21h
mov ah,1
int 21h
mov bh,al
sub bh,48
cmp bh,1
je p1699
cmp bh,2
je p200
cmp bh,3
je p200
cmp bh,4
je p600
cmp bh,5
je p50
cmp bh,6
je p129
cmp bh,7
je p300
cmp bh,8
je p200
p1699:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Imac2021
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p600:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, Storage9
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
p50:
mov dx, offset H74
mov ah, 09h
int 21h
mov ax, MagicTra
add total, ax
mov ax, total
mov value, ax
call display_number
call returnmenu
;returnmenu
returnmenu:
DISPLAY H68;
DISPLAY H10;
DISPLAY H69;
DISPLAY H71;
DISPLAY H72;
DISPLAY H10;
mov dx, offset H73
mov ah, 09h
int 21h
mov ah,1
int 21h
mov bh,al
sub bh,48
cmp bh,1
je Applewatch
cmp bh,2
je product
cmp bh,3
je over
display_number proc near
mov ax,value
xor cx,cx ;Counts the digits
mov bx,10 ;Fixed divider
more:
xor dx,dx ;Word division needs to zero DX!
div bx
push dx ;Remainder [0,9]
inc cx ;One digit more
test ax,ax
jnz more ;Continue until AX is empty
next:
pop dx
add dl,48 ;Turn into a character, from [0,9] to ["0","9"]
mov ah,02h ;DOS DisplayCharacter function
int 21h
loop next ;Continue for all digits (*)
ret
over:
DISPLAY 75;
DISPLAY 76;
DISPLAY 77;
DISPLAY 78;
DISPLAY 79;
DISPLAY 80;
DISPLAY 81;
DISPLAY 82;
DISPLAY 83;
DISPLAY 84;
DISPLAY 85
mov ah, 4ch
int 21h
end begin
ret
endp
我不太喜欢引入另一个菜单来定制、返回或退出。只要爬回菜单层次结构,保持简单。;prompt user H68 DB 10,13,10,13,10,13,'Do you still want to add on ?$' H69 DB 10,13,'1.To Customize more $' H71 DB 10,13,'2.To return to menu $' H72 DB 10,13,'3.To exit $' H73 DB 10,13,10,13,'Enter your choice here > $'
您有一个名为PRODUCTS的主菜单,您在程序中将其标记为product
。并且您有6个子菜单,您标记为Applewatch
,Iphone
,Airpod
,Macbook
,Ipad
和Imac
。
假设用户按下主菜单上的1,然后启动Applewatch
子菜单。在该子菜单中做出选择并处理产品后,您应该将jmp
返回到您期望在同一子菜单中输入的点。我在下面的代码片段中将其标记为ApplewatchInput
:
Applewatch:
DISPLAY H9
DISPLAY H10
DISPLAY H11
DISPLAY H12
DISPLAY H13
DISPLAY H14
DISPLAY H15
DISPLAY H16
DISPLAY H17
ApplewatchInput: <<< new
DISPLAY H18
mov ah, 1
int 21h
mov bh, al
sub bh, 48
cmp bh, 1
je p449
cmp bh, 2
je p19
cmp bh, 3
je p19
cmp bh, 4
je p10
cmp bh, 5
je p20
cmp bh, 6
je p79
jmp ApplewatchInput <<< new, What if user presses wrong key?
p449:
DISPLAY H74
mov ax, Apple_watch
add total, ax
mov ax, total
mov value, ax
call display_number
jmp ApplewatchInput <<< new, Replaces you 'call returnmenu'
在某些时候,用户会想要离开这个Applewatch
子菜单并进入主菜单。您可以为此包含一个额外的子菜单选项(也许是数字0 ?),或者您可以简单地考虑输入任何无效的选择作为跳转回主菜单(或任何高级菜单)的触发器:
...
cmp bh, 6
je p79
jmp product <<< new, User pressed wrong key, so back to main menu
p449:
DISPLAY H74
mov ax, Apple_watch
...
当然,您必须以类似的方式将上述所有内容应用于所有产品和所有子菜单。