x86-64 Linux程序集打印整数

时间:2013-07-23 15:19:39

标签: assembly x86-64

当我运行这个时,唯一发生的是一个seg错误......请帮我打印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

0 个答案:

没有答案