Author Topic: 64-bit effective addressing  (Read 12098 times)

Offline cre8eve

  • Jr. Member
  • *
  • Posts: 3
64-bit effective addressing
« on: November 25, 2014, 11:37:36 PM »
Hi. So I am trying to count number of symbols that were supplied into my input.
So I have reservation for input here:
Code: [Select]
section .bss
Buffer:         resb    64

Initialisation of length variable:
Code: [Select]
section .data
inputLength dw 0

I read the input into buffer by this function:
Code: [Select]
readInputIntoBuffer:
mov rax, 0x2000003
mov rdi, 0
mov rsi, Buffer
mov rdx, 63
syscall
ret

And now I am trying to count number of chars, comparing each one with 0x00
Code: [Select]
countLength:
mov rax, qword [Buffer]
cmp rax, 0
jg increaseLength
je done
jmp countLength


increaseLength:
mov r13, qword [inputLength]
inc r13
mov qword [inputLength], r13
done:
ret

But every time I get

Code: [Select]
error: Mach-O 64-bit format does not support 32-bit absolute addresses

What should I try?
Link for source code: https://www.dropbox.com/s/03z231zk6ejxt11/main.asm?dl=0
Thanks, Victor.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: 64-bit effective addressing
« Reply #1 on: November 26, 2014, 12:56:37 AM »
I think, to shut Nasm up, try:
Code: [Select]
default rel
at the top of your code. That's a WAG - I'm not familiar with macho64, but I'm told it works.

"dw" looks too small for "inputLength". It may work anyway - if there's nothing after it - but should probably be "dq".

I don't see how your "countLength" loop is going to advance. I think it's going to loop forever.

HTH

Best,
Frank




Offline cre8eve

  • Jr. Member
  • *
  • Posts: 3
Re: 64-bit effective addressing
« Reply #2 on: November 26, 2014, 02:07:03 AM »
Thank you so much! That did help, there is no more errors, however I am having trouble with the count.
After I read the input into Buffer, I want to go char by char at the Buffer address and examine wether it is greater than 0x00

Code: [Select]
countLength:
mov r12, [Buffer]
cmp r12, 0
jg increaseLength
je done
jmp countLength


increaseLength:
inc qword [inputLength]
done:
ret

But when I was debugging it in the Hopper disassembler, I found out that after this stage
Code: [Select]
mov r12, [Buffer]
r12 remains empty, and then it simply returns from this function without incrementing.
I examined the memory at Buffer address, and It was filled with 0x00!
But when I was calling display function
Code: [Select]
showBuffer:
mov rax, 0x2000004
mov rdi, 1
mov rsi, qword Buffer
mov rdx, 63
syscall
ret
it did print the Buffer without any problems.
Where could the problem be here?
 

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: 64-bit effective addressing
« Reply #3 on: November 26, 2014, 03:53:12 AM »
Quote
I examined the memory at Buffer address, and It was filled with 0x00!
I don't know what the problem could be there!

Assuming that you do have some non-zero characters in your buffer, I should think...
Code: [Select]
countLength:
mov r12, Buffer  ; address of buffer
.top:
        mov al, [r12] ; one 8-bit character
cmp al, 0
jg increaseLength
je done
        inc r12
jmp .top


increaseLength:
inc qword [inputLength]
; don't "fall through" here!
        jmp .top

done:
ret
... something like that. You can use some other 8-bit register if al is busy, but "mov some 8-bit reg, [some 64-bit reg]"... and increment the 64-bit reg to "walk" down the buffer. Can't test it for ya - haven't got a 64-bit machine (currently running) nor a Mac, but I think that "should work". But if the buffer is full of zeros... I dunno. Your sys_read looks right to me...

Best,
Frank