程序如果要啤酒,询问 [英] Program which asks if you want beer

查看:168
本文介绍了程序如果要啤酒,询问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个程序,如果你要啤酒(仅大于或等于18岁),询问。
我的报告汇编的一些问题。我在8086汇编初学者。

I wrote a program that asks if you want a beer (only larger than or equal to 18 years old). My assembler reports some problems. I'm a beginner in 8086 assembly.

    .MODEL SMALL
    .STACK 100h
    .DATA

  Welcome DB 'Hello man, How old are you?',13,10,'$'                                    
  beer DB 'Did you want to drink a beer?(y/n)',13,10,'$'
  old DB 'You cant drink becuste are you young',13,10,'$'   
  yes DB 'Ok thanks, pay 5$ in cash',13,10,'$' 
  no DB 'Ok, so **** you off!',13,10,'$'


    .CODE

    Welcom:  

        MOV AX, @DATA              
        MOV DS, AX                 
        MOV AH, 9                   
        MOV DX, OFFSET Welcome     
        INT 21h                    

        MOV AL, 1
        INT 21h       

        CMP AL, 18
        JB older 
        CMP, AL, 18 
        JAE drink

        MOV AX, 1 
        INT 21h  
        CMP AL, 'y'
        JE ye
        CMP AL, 'n'
        JE n

      older:


            MOV DX, OFFSET old 


      drink:  


            MOV DX, OFFSET beer



      ye:  


            MOV DX, OFFSET yes


      n:

            MOV DX, OFFSET no

     xx:

         MOV AX, 4ch 
         INT 21h     
         END Welcome

感谢

推荐答案

您不希望在 CMP,AL,18 的CMP后一个逗号。而你并不需要第二CMP反正因为条件跳转不会从previous CMP影响标志。

You don't want a comma after the CMP in CMP, AL, 18. And you don't need the 2nd CMP anyway because a conditional jump doesn't affect the flags from the previous CMP.

您可能不应该使用其他条件跳转下去,但以后你会学到。

You probably shouldn't be using another conditional jump either, but you'll learn that later.



至于你的第二个问题,你把END欢迎,而不是END开山鼻祖,而我在猜测的字符串设定的程序开始在数据段开头的你好。在'E'是字符code 65(十六进制)。一般情况下,它不使用标签这是如此的相似是个好主意。也许使数据字符串标签问候,并留下欢迎,为code,在这种情况下,您可以留下您的END语句,因为它是。


As for your second question, you put "END Welcome" instead of "END Welcom", which I'm guessing set the program start in the DATA section at the string beginning "Hello". The 'e' is character code 65 (hex). In general, it's not a good idea to use labels which are so similar. Maybe make the data string label "greeting", and leave "Welcome" for the code, in which case you can leave your END statement as it is.

这篇关于程序如果要啤酒,询问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆