How to print a number in x64 windows Assembly

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 4146 Views - Last Post: 11 August 2012 - 10:03 AM

#16 davetheant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 10-August 12

Re: How to print a number in x64 windows Assembly

Posted 11 August 2012 - 09:22 AM

Jer is my buffer. I realized that there is a problem earlier in the code; it crashes whenever I try to do a 'movsq'. I don't understand why; from what I've read it seems right.
Jer rq 256
Message db ?,0



Here is what I'm trying to do when movsq crashes the program:
 mov rdi, [Jer]  ;store address of buffer in rdi
 add rdi,6;[numdigs]    ;length of number is 6 digits
 mov qword rsi, 0 ;put a 0 into the source register
 movsq


Was This Post Helpful? 0
  • +
  • -

#17 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,287
  • Joined: 28-March 11

Re: How to print a number in x64 windows Assembly

Posted 11 August 2012 - 09:29 AM

mov rdi, [Jer] is NOT storing the address of Jer in rdi, it is storing the CONTENTS of Jer.

mov rdi, Jer would store the address of Jer.

I forgotten to give you the link to Art of Assembly - http://www.plantatio...TML/AoATOC.html

Do you want the BOX, or what's IN the [BOX].

add rdi,6;[numdigs], if numdigs contains 6, then you can just do add rdi, [numdigs]
Was This Post Helpful? 0
  • +
  • -

#18 davetheant  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 10-August 12

Re: How to print a number in x64 windows Assembly

Posted 11 August 2012 - 10:03 AM

Oohkay I was confused about that. Now Im finally getting working code and the messagebox comes up but there's no message text! So close!

If I'm keeping each digit as a quad-word then I need to add 8*the number of digits to rdi, right? And I believe forgot to compensate for the 00 end of string.

mov rdi, Jer     ;move address of Jer to rdi
add rdi,56       ; 7 digits (including 00) * 8 (quadword) = 56
mov qword rsi, 0 ;load 0 into the source 
mov qword [rdi],rsi ;manually moving instead of movsq
sub rdi,8        ;move rdi back 8 places 

mov dword ecx,10
Loopp:
dec rdi
                xor rdx,rdx ; clear rdx for division

                div ecx ; divide by 10
                movsxd rdx,edx ; store digit onto rdx
                add rdx,48 ;convert to ascii
                mov qword rsi,rdx ;load digit into source

                mov qword [rdi],rsi ;instead of movsq
                sub rdi,8 ;move rdi back more places
                test eax,eax
                jnz L  

;Printing:
xor r9d,r9d
                mov rdx, Jer ; Not sure if I'm supposed to be moving the address or the contents, but I tried both 
                xor rcx,rcx
                call [MessageBox]
                mov ecx,eax
                invoke ExitProcess,0



Any help is greatly appreciated
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2