I have read that Assembly language is processor dependent, and there were special set of instructions for every processor. I use intel i5 x86_64 architecture processor. When I write code I haven't used any different set of instructions. I use NASM assembler. It assembles my code and converts to binary. So Whats the matter with Processor there. Even my friend with different architecture runs the same code (not compiled but source code) and gets the same Output... So where is Assembly language processor dependent ??
And the code is ... Its just an example, every piece of code runs on both architectures x86_64 and 8088 microprocessor
[ORG 0x7c00]
xor ax, ax ;make it zero
mov ds, ax
mov si, msg
call bios_print
hang:
jmp hang
msg db 'Welcome to Macintosh', 13, 10, 0
bios_print:
lodsb
or al, al ;zero=end of str
jz done ;get out
mov ah, 0x0E
int 0x10
jmp bios_print
done:
ret
times 510-($-$$) db 0
db 0x55
db 0xAA
There are diffent layers of processor dependcy. Intel made a lot of effort to make subsequent CPUs compatible to prior CPUs of their family, so it's entirely possible to write code which runs on multiple "different" CPUs.
However, when you try to write some assembly code, which takes advantage of the specific features, this is no longer true. And if you try to write high performance code the rules are also changing on different CPUs even from the same family.
If you look at the instruction set from Intel and comapre them to older ones, you will easily see that newer CPUs have also new instructions that were not available before.
And also the OS takes a role in that, by providing support for older programs. For example you could run 16-Bit applications natively until Windows XP. In Windows 7 64bit the support was dropped. So when running such code, you may not even have noticed that there is a layer of support that makes your prorgam still working.