Author Topic: Trying 64-bit on AMD with OpenBSD  (Read 9688 times)

Offline MrCBofBCinTX

  • Jr. Member
  • *
  • Posts: 18
    • Capuchado!
Trying 64-bit on AMD with OpenBSD
« on: March 24, 2014, 09:21:25 PM »
After seeing a hello world in 64-bit, I decided to try some very simple 64-bit.

Code: [Select]
section .note.openbsd.ident
 align 2
 dd 8
 dd 4
 dd 1
 db 'OpenBSD',0
 dd 0
 align 2


section .data
A db 22h, 69h, 6Ch, 'l', ' the', ' birds!', 7Eh, 10 ; Kill the birds!~
Abytes  equ $-A
B dw 0022h, 0069h, 006Ch, 'l', ' the', ' birds!', 007Eh, 10 ; Kill the birds!~
Bbytes  equ $-B
C dq 00000022h, 00000069h, 0000006Ch, 'l', ' the', ' birds!', 0000007Eh, 10 ; Kill the birds!~
Cbytes  equ $-C

section .text
global  _start
_start:

add byte [A], 29h
add byte [A+1], 10
add byte [A+2], 10

mov rax, 4
mov rdi, 1
mov rsi, A
mov rdx, Abytes

    syscall

add dword [B], 29h
add dword [B+2], 10
add dword [B+4], 10
mov rax, 4
mov rdi, 1
mov rsi, B
mov rdx, Bbytes

    syscall

add qword [C], 29h
add qword [C+8], 10
add qword [C+16], 10

mov rax, 4
mov rdi, 1
mov rsi, C
mov rdx, Cbytes

    syscall

    mov rax, 1
    xor   rdi, rdi

    syscall


Using to assemble:
Code: [Select]
nasm -f elf64 -o ADD1.o ADD1.asm
ld -m elf_x86_64_obsd -o ADD1 -nopie ADD1.o

I get, as expected:

Code: [Select]
$ ADD1                                                                           
Ksvl the birds!~
Ksvl the birds!~
Ksvl the birds!~


but I can use either byte or word here:

Code: [Select]
add byte [A], 29h
add byte [A+1], 10
add byte [A+2], 10

or

add word [A], 29h
add word [A+1], 10
add word [A+2], 10

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Trying 64-bit on AMD with OpenBSD
« Reply #1 on: March 24, 2014, 10:18:33 PM »
Nice example of the required "magic" for OpenBSD!

So...
Code: [Select]
add byte [A], 29h
add byte [A+1], 10
add byte [A+2], 10

or

add word [A], 29h ; add 29h to [A] and add 0 to [A+1]
add word [A+1], 10 ; add 10 to [A+1] and add 0 to [A+2]
add word [A+2], 10 ; add 10 to [A+2] and add 0 to [A+3]

You do a similar thing with adding dwords to B. I don't know what you intend to do here. I don't know why you're printing all those zeros. I don't know what you've got against the birds. Thanks for the example anyway! :)

Best,
Frank



Offline MrCBofBCinTX

  • Jr. Member
  • *
  • Posts: 18
    • Capuchado!
Re: Trying 64-bit on AMD with OpenBSD
« Reply #2 on: March 25, 2014, 10:34:45 AM »
The "magic" for OpenBSD keeps changing!
I thought it might be useful to have something posted as an example.

Just joking about the birds (chickens).
Owner stopped feeding them so we throw them wild bird seed.

Wanted to see if I was doing anything wrong, right answer doesn't always mean doing the right thing.
Thought I would learn 64-bit since everything I have except for my "classic" laptops will run it.