“汇编语言 - 如何添加我将选择的项目并将其减去现金?”

时间:2015-03-07 23:01:28

标签: assembly x86 dos

如何添加我将选择的项目并从我将输入的现金中减去它?

org 100h   
LEA DX, ASKQUESTION     ;Ask question to proceed or quit
MOV AH, 09H
INT 21H

MOV AH, 01H
INT 21H

CMP AL, 71h
JE PQ
JNE PROCEED

PROCEED:
LEA dx, NEWLINE         ;new line
MOV ah, 9h 
INT 21h 

LEA dx, CHOOSE          ;Choose msg
MOV ah, 9h 
INT 21h 

LEA DX, PROD1
MOV AH, 9H
INT 21H 

LEA DX, PROD2
MOV AH, 9H
INT 21H

LEA DX, PROD3
MOV AH, 9H
INT 21H

LEA DX, PROD4
MOV AH, 9H
INT 21H

LEA DX, NEWLINE
MOV AH, 9H
INT 21H  

GETITEM:
LEA DX, ITEM  
MOV AH, 09h
INT 21h

MOV AH, 01h
INT 21H

CMP AL, 0dh
JE NOTICE                 ;jump if AL=0dh to NOTICE 

CMP AL, 31h
JE l1

CMP AL, 32h
JE l2 

CMP AL, 33h
JE l3

CMP AL, 34h
JE l4
JNE WARNING

l1:                       ;firstItem
MOV CL, 36h
MOV BL, 35h
MOV ITM11, CL
MOV ITM12, BL 

JMP GOLOOPING

l2:                       ;2ND ITEM
MOV CH, 34H
MOV BH, 35H
MOV ITM21, CH
MOV ITM22, BH

JMP GOLOOPING

l3:                        ;THIRD ITEM 
MOV CH, 32H
MOV CL, 30H
MOV ITM31, CH
MOV ITM32, CL

JMP GOLOOPING

l4:                        ;4TH ITEM 
MOV BH, 38H
MOV BL, 30H
MOV ITM41, BH
MOV ITM42, BL


GOLOOPING:
LEA DX, LOOPING
MOV AH, 09H
INT 21H

MOV AH, 01H
INT 21H

CMP AL, 79h
JNE GOPAYMENT
JE GETITEM

NOTICE: 
LEA DX, NOTICEMSG
MOV AH, 09h
INT 21h

JMP GETITEM

WARNING:
LEA DX, OOPS
MOV AH, 09H
INT 21H

JMP GETITEM

PQ:                 ;proceed or Quit
LEA DX, QUIT
MOV AH, 09H
INT 21H

INT 20h             ;to terminate program

GOPAYMENT:
LEA DX, NEWLINE
MOV AH, 09H
INT 21H

LEA DX, PAYMENT
MOV AH, 09H
INT 21H  

LEA DX, NEWLINE
MOV AH, 09H
INT 21H

LEA DX, CASH
MOV AH, 09H
INT 21H

MOV AH, 01H
INT 21H
MOV BH, AL

MOV AH, 01H
INT 21H
MOV BL, AL

MOV AH, 01H
INT 21H
MOV CL, AL

CHOOSE DB 13,10, " CHOOSE PRODUCT: $"
PROD1 DB 13,10, "   1. WATERMELON   P65$"  
PROD2 DB 13,10, "   2. MELON        P45$"
PROD3 DB 13,10, "   3. Banana       P20$"
PROD4 DB 13,10, "   4. Mango Steam  P80$"

NEWLINE DB 13,10, " $" 
SHOWPRICEITEMS DB 13,10, "  P $" 
ITEM DB 13,10, "Enter item: $"
LOOPING DB 13,10, "Do you want to choose more(y/n)? $"
PAYMENT DB 13,10, "--------PAYMENT--------$"
CASH DB 13,10, "    Cash:        $"
NOTICEMSG DB 13,10, "NOTICE: You need to input items.$"
OOPS DB 13,10, "Wrong Input!"
ASKQUESTION DB 13,10, "Want to proceed or quit(p/q)?$"
QUIT DB 13,10, "----Bye-------$"

ITM11 DB 00H
ITM12 DB 00H
ITM21 DB 00H
ITM22 DB 00H
ITM31 DB 00H
ITM32 DB 00H
ITM41 DB 00H
ITM42 DB 00H  

end

1 个答案:

答案 0 :(得分:0)

您应该首先将现金转换为整数。

LEA DX, CASH
MOV AH, 09H
INT 21H

MOV AH, 01H
INT 21H
sub al,48
mov ah,100
mul ah
mov bx,ax

MOV AH, 01H
INT 21H
sub al,48
mov ah,10
mul ah
add bx,ax

MOV AH, 01H
INT 21H
sub al,48
mov ah,0
add bx,ax

接下来将item1的值转换为另一个整数,并从BX寄存器中的 cash 整数中减去它。只有当item1被有效购买时才这样做!

DeductItem1:
 mov al,ITM11
 cmp al,0
 je Item1WasNotBought
 sub al,48
 mov ah,10
 mul ah
 mov cx,ax

 mov al,ITM12
 sub al,48
 mov ah,0
 add cx,ax

 sub bx,cx
Item1WasNotBought:

对第2,3和4项重复上一步。

现在BX持有现金返还。