NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: nasmpc on August 19, 2018, 06:23:28 PM
-
.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?
-
ld -o garbage garbage.o someotherfile.o
Is this a trick question?
Sincerely,
Frank
-
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.
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
-
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.
; 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/
-
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
-
; 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?
-
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:
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.
; nasm -f bin hello.asm -o hello.com
mov ah, 9
mov dx, msg
int 21h
ret
msg db "Hello World!$"
Best,
Frank
-
This question is to whether you need to use special keys in the ld linker when using the ah registers?
-
Frank I do not use dos
-
and the main thing I'm very glad that you understood my question correctly