Author Topic: ld  (Read 1040 times)

Offline nasmpc

  • Jr. Member
  • *
  • Posts: 15
ld
« on: August 19, 2018, 06:23:28 PM »
Code: [Select]
.text
        .global _start
_start:
          movb $4, %ah
          movb $1, %bh
          mov   $stroka, %rcx
          mov   $len,    %rdx

         int $0x80



gcc -c file.s
ld   -?



what keys to specify ld?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2373
  • Country: us
Re: ld
« Reply #1 on: August 19, 2018, 07:17:59 PM »
Code: [Select]
ld -o garbage garbage.o someotherfile.o

Is this a trick question?

Sincerely,
Frank


Offline nasmpc

  • Jr. Member
  • *
  • Posts: 15
Re: ld
« Reply #2 on: August 19, 2018, 07:49:26 PM »
hi Frank


I ask only honest questions I do not know how to use the correct registers 8 bit ah al can any example to write the use of these registers in the program for 64 bit Linux.



Code: [Select]
section .data
      num db '10'
section .text
      global _start
_start:
          mov 0+ah, 4 -wrong
          mov ah, 4?
          how right?


         mov rbx, 1
         mov rcx, num


nasm -f elf-?
ld- ?

any simple example write please

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2373
  • Country: us
Re: ld
« Reply #3 on: August 19, 2018, 09:34:29 PM »
Okay, sorry.

Everything is different in 64-bit code. The system call numbers are different. The parameters go in different registers. We use "syscall" (an instruction) instead of "int 0x80". I guess the error numbers are the same.

I think this is correct.
Code: [Select]

; nasm -f elf64 hello64.asm
; ld -o hello64 hello64.o

global _start ; tell Nasm to tell ld about this
section .text

_start:  ; default entrypoint for ld

mov rax, 1 ; sys_write
mov rdi, 1 ; stdout
mov rsi, msg ; address of string
mov rdx, len ; length of string
syscall

mov rax, 60 ; sys_exit
mov rdi, 42 ; we can see it with "echo $?"
syscall

section .data
msg db "Hello World!", 10
len equ $ - msg ; "$" means "here"

It "seems to work".

There is a tutorial by Ray Toal. I'll see if I can find it...

Best,
Frank

here ya go:
http://cs.lmu.edu/~ray/notes/nasmtutorial/
« Last Edit: August 19, 2018, 09:45:38 PM by Frank Kotler »

Offline nasmpc

  • Jr. Member
  • *
  • Posts: 15
Re: ld
« Reply #4 on: August 20, 2018, 02:07:53 PM »

Frank and where are registers ah and others in your program? Use them too, please. I want you to use the 64-bit code register ah

Offline nasmpc

  • Jr. Member
  • *
  • Posts: 15
Re: ld
« Reply #5 on: August 20, 2018, 02:09:48 PM »
Code: [Select]






; nasm -f elf64 hello64.asm
; ld -o hello64 hello64.o

global _start ; tell Nasm to tell ld about this
section .text

_start:  ; default entrypoint for ld

mov ah, 1 ; sys_write
mov rdi, 1 ; stdout
mov rsi, msg ; address of string
mov rdx, len ; length of string
syscall

mov rax, 60 ; sys_exit
mov rdi, 42 ; we can see it with "echo $?"
syscall

section .data
msg db "Hello World!", 10
len equ $ - msg ; "$" means "here"








like this. how to compile it?

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2373
  • Country: us
Re: ld
« Reply #6 on: August 20, 2018, 04:47:29 PM »
ah is an 8-bit register. It's the high part of ax, part of eax, part of rax. Sane place it's always been.

If you really want to use ah:
Code: [Select]
xor rax, rax
mov ah, 1
; now rax is 16 - sys_ioctl

In DOS, ah controls the subfunction of int 21h. If you want to use ah for practical purposes, you may want to install DosBox.
Code: [Select]
; nasm -f bin hello.asm -o hello.com
mov ah, 9
mov dx, msg
int 21h
ret
msg db "Hello World!$"

Best,
Frank


Offline nasmpc

  • Jr. Member
  • *
  • Posts: 15
Re: ld
« Reply #7 on: August 20, 2018, 05:33:09 PM »
This question is to whether you need to use special keys in the ld linker when using the ah registers?

Offline nasmpc

  • Jr. Member
  • *
  • Posts: 15
Re: ld
« Reply #8 on: August 20, 2018, 05:34:13 PM »

Frank I do not use dos

Offline nasmpc

  • Jr. Member
  • *
  • Posts: 15
Re: ld
« Reply #9 on: August 20, 2018, 05:35:43 PM »
and the main thing I'm very glad that you understood my question correctly