微机原理编程

编程求N=1+2+3+…+n的最大值,使N不超过16位数的表示范围?
2024-11-25 21:42:03
推荐回答(1个)
回答1:

        CODE  SEGMENT
              ASSUME    CS:CODE
      START:  PUSH      CS
              POP       DS
              PUSH      CS
              POP       ES
              MOV       CX,10000
              MOV       DX,1
              MOV       AX,0
         @1:
              ADD       AX,DX
              JC        @2          ; 有符号数范围则 改为 jo @2
              INC       DX
              LOOP      @1
         @2:
              MOV       AX,DX
              DEC       DX
              MOV       AX,DX
              MOV       BX,10
              CALL      DSPAXX
              MOV       AH,4CH
              INT       21H

;================================  
     ; 输出ax的值,输出的进位制在bx中设定,bx=2~16  
      DSPAXX  PROC      NEAR
              PUSH      AX
              PUSH      BX
              PUSH      CX
              PUSH      DX
              PUSHF
              XOR       CX,CX
              ; MOV       BX,16
  @DSPAXX_1:
              XOR       DX,DX
              DIV       BX
              INC       CX
              OR        DX,30H
              PUSH      DX
              CMP       AX,0
              JNE       @DSPAXX_1
              MOV       AH,2
 @DISPAXX_2:
              POP       DX
              CMP       DL,3AH
              JB        @DISPAXX_3
              ADD       DL,7
 @DISPAXX_3:
              INT       21H
              LOOP      @DISPAXX_2
              MOV       DL,32
              INT       21H
              POPF
              POP       DX
              POP       CX
              POP       BX
              POP       AX
              RET
      DSPAXX  ENDP
;===============================
 
        CODE  ENDS
              END       START