0

运行此程序时唯一发生的事情是段错误...请帮我打印从 99 到 0 的数字!

这都是 64 位的......而且我知道 SINGLE_DIGIT 没有做任何事情,但即将到来。谢谢你的帮助!

GLOBAL  _start
SECTION .TEXT

_start:
 MOV RCX,99

 Loopy:
  CMP RCX,10
  JGE TWO_DIGIT
  JMP ONE_DIGIT

  TWO_DIGIT:
   MOV RAX,RCX      ;MOV NUMBER INTO RAX
   MOV RBX,10
   IDIV RBX     ;DIVIDE RAX BY TEN
   MOV RBX,'0'      ;OFFSET TO ACSII 0
   ADD RBX,RAX      ;ADD TO THAT OFFSET TO GET TO NUMBER

   MOV RAX,1        ;PRINTING 
   MOV RDI,1
   PUSH RCX
    MOV RCX,NUMBER
    ADD [RCX],RBX       ;CHANGED NUMBER TO RCX
    MOV RSI,RCX     ;SET ACSII OF NUMBER TO RSI
   POP RCX
   PUSH RDX
    MOV RDX,1
    SYSCALL     ;PRINT
   POP RDX

   MOV RAX,1
   MOV RDI,1
   MOV RBX,'0'      ;RESET OFFSET
   ADD RBX,RDX      ;ADD REMAINER
   PUSH RCX
    MOV RCX,NUMBER
    ADD [RCX],RBX
    MOV RSI,RCX
   POP RCX
   MOV RDX,1
   SYSCALL      ;PRINT   

   DEC RCX
   CMP RCX,0
   JLE EndLoop
   JMP Loopy
  EndLoop:

  ONE_DIGIT:

 ;SYS_EXIT(RETURN_CODE)

 MOV RAX,60      ; SYS_EXIT
 MOV RDI,0       ; RETURN 0
 SYSCALL

SECTION .DATA

 LETTER EQU 1
 NUMBER: DB 0
4

0 回答 0