NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: gygzkunw on June 02, 2020, 04:01:00 PM
-
Good day
I am trying to get the user to get the user to input a state so i can print it out. I am using nasm, linux, x86
section .bss ; you can change
user_input: resb 256 ;256 byte of memory is reserved and can be accessed through the name user_input
user_input_size equ $- user_input
section .data ;you cant change
output: db "Enter your print statement: "
output_size equ $- output
section .text ;assembly code
global _start
_start:
mov eax, 4
mov ebx, 1
mov ecx, output
mov edx, output_size
int 80
mov eax, 3
mov ebx, 0
mov ecx, user_input
mov edx, user_input_size
int 80
push ecx ; not sure about this
push edx ; not sure about this
mov eax, 4
mov ebx, 0
pop ecx
pop edx
int 80
mov eax, 1
mov ebx, 0
int 80
I am unable to enter anything. I am using an online compiler and it is showing the following;
.code.tio.s:25: error: instruction not supported in 64-bit mode
.code.tio.s:26: error: instruction not supported in 64-bit mode
.code.tio.s:30: error: instruction not supported in 64-bit mode
.code.tio.s:31: error: instruction not supported in 64-bit mode
ld: cannot find .obj.tio: No such file or directory
/srv/wrappers/assembly-nasm: line 6: ./.bin.tio: No such file or directory
-
Hi gygzkunw,
Welcome to the forum.
I'm a little confused. That's okay, I think you're a little confused, too (no offense intended).
I don't know what an "online compiler" is, but obviously it's trying to assemble 64-bit code. Pushing/ popping 32-bit registers won't work in 64-bit code...
Your code looks pretty good for 32-bit... except that you want "int 80h" (or 0x80) not "int 80".
You want to tell nasm:
nasm -f elf32 myprog.asm
(or whatever you called it)
and tell ld:
ld -o myprog myprog.o -m elf_i386
Or... if your online compiler insists on 64-bit code... uhhh... your code might work without the push/pop - and int 80h. But 64-bit code might be better...
If it'll help... sys_read will return the number of bytes read in eax. Just put that in edx - ecx should still have the input buffer...
Let us know how it goes...
Best,
Frank
-
Yeah i was confused i blame my hunger for that... I got the code to work
section .bss
user_input resb 25 ; user input
user_input_length equ $- user_input
section .text
global _start
_start:
mov eax, 3 ; sys_read
mov ebx, 0 ; stdin
mov ecx, user_input ; user input
mov edx, user_input_length ; max length
int 80h
mov eax, 4 ; sys_write
mov ebx, 1 ; stdout
mov ecx, user_input ; buffer
mov edx, user_input_length ; length
int 80h
mov eax, 1
mov ebx, 0
int 80h
I need some clarification
ex1: resb 1 -> reserves 1 byte
ex2: db 1 -> reserves a byte that contains 1
ex3: db "cool" -> reserves 4 bytes and each byte contains a letter
ex4: db "cool", 1, 3 -> reserves 3 bytes?
-
ex4: db "cool", 1, 3 -> reserves 3 bytes?
6 bytes. the 4 letters "cool", the byte 1, and the byte 3
db "cool", 13, 10 would be "cool " and a newline (carriage return and linefeed)
Glad you got your code working.
Best,
Frank
-
Sweet thanx.
-
ex4: db "cool", 1, 3 -> reserves 3 bytes?
6 bytes. the 4 letters "cool", the byte 1, and the byte 3
db "cool", 13, 10 would be "cool " and a newline (carriage return and linefeed)
Glad you got your code working.
Best,
Frank
sorry I didn't think it make sense to start a new topic since my question is regarding the above.
I have am still reading Jeff programming in Linux and i have a question. He stated that appending any number to a string and the OS will read it as an ascii character. Hence
db "cool", 13, 10 would be "cool " and a newline (carriage return and linefeed)
what of if i just do
ex4: db 10, 13 -> will the OS read these number as ascii characters (carriage return and linefeed) or integers?
-
apparently
ex4: db 10, 13 will be read as ASCII character. I did
ex4: db 49 and the character 1 was printed out