Recent Posts

Pages: 1 2 [3] 4 5 ... 10
NASM is an assembler, not a compiler of a high-level language. So it just "translates" the instructions specified in the .asm source into the corresponding opcodes.
There's no CPUID checking or emulation - that's up to you, as the author of the .asm source.
So yes, if you use a new instruction and run the compiled executable on a CPU that doesn't support it (and the execution actually reaches that instruction), the program will crash.

Yes, NASM supports recent additions. I'm not aware of any missing x86 instructions for existing CPUs. (Well, except for a few of those that are not actually documented anywhere, such as some of the Via/Zhaoxin instructions).
As you know, most CPUs implement the x86-64 instruction set.
NASM is more or less build to allow programmers to easily write more or less x86-64 code...
I don't doubt that it does this properly...

However, due to the x86-64 standard being pretty old, many chip producers designed their chips in a way so that they could do more...
By adding new instructions...

Some of these "additions", I see, are part of NASMs repertoire...

That leads to a few questions:

What are these NASM instructions compiled to? Are they compiled to the corresponding x86-64 additive instructions, or are they rather emulated using normal x86-64 instructions?

What happens if I run a NASM program containing such instructions on a CPU that does not support them? will the program crash? Or does NASM make the programs in a way such that they, for example, check the CPU kind on startup and adapt?

Does NASM cover all important additions made to the x86-64 instruction set over the past decades?
Example Code / Re: Hello World
« Last post by Frank Kotler on June 09, 2020, 02:42:43 AM »
No. int 0x10 is BIOS code.  It is 16 bit code.

If you want something for Windows, look into WriteFile.


Example Code / Re: Hello World
« Last post by michaellongge on June 08, 2020, 06:52:14 PM »
cant run on win7
Programming with NASM / Re: writefile with NASM
« Last post by Frank Kotler on June 06, 2020, 10:41:41 PM »
Okay. That's for Linux. Windows will be different, but same general idea. First, you'll have to open the file. to get a file "descriptor" or "handle". This will want a pointer to a filename (obviously), whether it's read/write or both, maybe some "permissions"... ownership... etc. MicroSoft has a;; this pretty well documented. Search for "OpenFile", "WriteFile", etc. It will not be in assembly language. Where they do "foo", we have to do "call foo". You'll figure it out. If you have trouble, post what you've got... You might even get someone running Windows to help...


Programming with NASM / Re: writefile with NASM
« Last post by assistech on June 06, 2020, 09:53:13 PM »

Hey, have you ever read this :

I will try it on Windows
Programming with NASM / Re: Input and Output
« Last post by gygzkunw on June 03, 2020, 09:00:37 PM »
Sweet thanx.
Programming with NASM / Re: Input and Output
« Last post by Frank Kotler on June 03, 2020, 08:06:09 PM »
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.


Programming with NASM / Re: Input and Output
« Last post by gygzkunw on June 03, 2020, 06:57:37 PM »
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
         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?
Programming with NASM / Re: Input and Output
« Last post by Frank Kotler on June 02, 2020, 10:07:32 PM »
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:
Code: [Select]
nasm -f elf32 myprog.asm
(or whatever you called it)
and tell ld:
Code: [Select]
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...


Pages: 1 2 [3] 4 5 ... 10