微机原理程序汇编语言,鸡兔同笼,总头数为H,总脚数为F,笼中鸡兔各有多少只以十进制形式显示在屏幕上 5

 我来答
永恒pascal
2018-09-05 · TA获得超过4357个赞
知道大有可为答主
回答量:3902
采纳率:93%
帮助的人:664万
展开全部
;  微机原理程序汇编语言,鸡兔同笼  H   F
;  x+y=h
;  2x+4y=f
;  y = (f-2h)/2 = f/2-h
;  x = h-y = 2h-f/2

        CODE  SEGMENT
              ASSUME    CS:CODE
           H  DW        ?
           F  DW        ?
           X  DW        ?
           Y  DW        ?
         MSG  DB        'please input H,F=$'
        MSG2  DB        'chicken,rabbit=$'
        
      START:  PUSH      CS
              POP       DS
              PUSH      CS
              POP       ES
              LEA       DX,MSG
              MOV       AH,9
              INT       21H
              CALL      INPUTNUM
              CALL      LFCR
              MOV       AX,WORD PTR ARRAY
              MOV       H,AX
              MOV       AX,WORD PTR ARRAY+2
              MOV       F,AX
              SHR       F,1
              JC        START       ; 不能整除转
              MOV       AX,F
              SUB       AX,H
              JS        START       ; 不够相减转
              MOV       Y,AX
              MOV       AX,H
              SHL       AX,1
              SUB       AX,F
              JS        START       ; 不够相减转
              MOV       X,AX
              LEA       DX,MSG2
              MOV       AH,9
              INT       21H
              MOV       AX,X
              CALL      DSPAX
              MOV       AX,Y
              CALL      DSPAX
              MOV       AH,4CH
              INT       21H

;===============================================
;  键盘输入数值数组子程序(数组名为array,元素个数存放在num中)
    INPUTNUM  PROC      NEAR
              PUSH      AX
              PUSH      BX
              PUSH      CX
              PUSH      DX
              PUSH      SI
              PUSH      DI
              PUSH      BP
              PUSHF
    ; 输入的数据以一个空格分隔,以回车符结束输入
              LEA       DI,CS:ARRAY
              MOV       WORD PTR CS:NUM,0
       STIN:
              MOV       AX,0
              PUSH      AX
     AGAIN1:
              MOV       AH,0CH
              MOV       AL,1
              INT       21H
              MOV       BYTE PTR CS:CHAR,AL
              CMP       AL,13
              JE        LINE0
              CMP       AL,' '
              JE        LINE0
              SUB       AL,30H
              MOV       AH,0
              MOV       SI,AX
              POP       AX
              MOV       CL,10
              MOV       CH,0
              MUL       CX
              ADD       AX,SI
              PUSH      AX
              JMP       AGAIN1
      LINE0:
              POP       AX
              MOV       WORD PTR CS:[DI],AX
              INC       WORD PTR CS:NUM
              CMP       BYTE PTR CS:CHAR,13
              JE        STINEND
              INC       DI
              INC       DI
              JMP       STIN
    STINEND:
              POPF
              POP       BP
              POP       DI
              POP       SI
              POP       DX
              POP       CX
              POP       BX
              POP       AX
              RET
       ARRAY  DW        200 DUP(0)
         NUM  DW        0
        CHAR  DB        ?
    INPUTNUM  ENDP
;=====================================
      DSPAXS  PROC      NEAR
              PUSH      AX
              TEST      AX,8000H
              JNS       @DSPAXS1
              PUSH      AX
              PUSH      DX
              MOV       AH,2
              MOV       DL,'-'
              INT       21H
              POP       DX
              POP       AX
              NEG       AX
   @DSPAXS1:
              CALL      DSPAX
              POP       AX
              RET
      DSPAXS  ENDP
;===================================
       DSPAX  PROC      NEAR
              PUSH      AX
              PUSH      BX
              PUSH      CX
              PUSH      DX
              PUSHF
              XOR       CX,CX
              MOV       BX,10
    @DSPAX1:
              XOR       DX,DX
              DIV       BX
              INC       CX
              OR        DX,30H
              PUSH      DX
              CMP       AX,0
              JNE       @DSPAX1
              MOV       AH,2
   @DISPAX2:
              POP       DX
              INT       21H
              LOOP      @DISPAX2
              POPF
              MOV       DL,32
              INT       21H
              POP       DX
              POP       CX
              POP       BX
              POP       AX
              RET
       DSPAX  ENDP
;===================================  
        LFCR  PROC      NEAR
              PUSH      AX
              PUSH      DX
              MOV       AH,2
              MOV       DL,13
              INT       21H
              MOV       DL,10
              INT       21H
              POP       DX
              POP       AX
              RET
        LFCR  ENDP
;=====================================                    
        CODE  ENDS
              END       START
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式