15 replies to this topic
#1
Posted 18 November 2010 - 09:30 AM
Please advise me some good tutorial on Assembler.
|
|
|
#2
Posted 18 November 2010 - 09:36 AM
We have a fine index of assembly tutorials here at our site:
Assembly Tutorials
You may wish to start with the "Intro to Intel Assembly Language" one.
Assembly Tutorials
You may wish to start with the "Intro to Intel Assembly Language" one.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 24 November 2010 - 09:44 PM
Hey guys, can you please suggest me a good eBook? I found some but I don't know which one to use. I correctly have "Programming Ground Up", "The Art Of Assembly Language", and "PC Assembly". Can you advice a good eBook?(Let me remind you that I'm using Gentoo and NASM).
Thanks
Thanks

There is no problem that cannot be solved by the use of high explosives.
#4
Posted 25 November 2010 - 12:02 AM
#5
Posted 25 November 2010 - 10:34 AM
Yeah I already have it. I asked which one of the mentioned is best or if there's any better one you may know, but I'm staying with AOAL.
Thanks anyway :)
-EDIT-
Holy netbooks, this thing has 1361 pages of pure Assembly! This is gonna take some time to learn, considering that I'm not even done with C. :w00t:
Thanks anyway :)
-EDIT-
Holy netbooks, this thing has 1361 pages of pure Assembly! This is gonna take some time to learn, considering that I'm not even done with C. :w00t:

There is no problem that cannot be solved by the use of high explosives.
#6
Posted 25 November 2010 - 12:13 PM
#7
Posted 26 November 2010 - 03:00 AM
God, I'm really starting to like this Assembly thingy, even before I finished the introduction. It says that ASM is light, and I was like "Really? How light?", so I tested it. Here's Hello World in C -
Size - 1.50 KB (1,536 bytes).(Tiny C Compiler)
Just cause I was curious, I compiled it with Borland TurboC 3.0.
6.93 KB (7,106 bytes). Geez.
Here's a Hello World for NASM -
Copied from Wikipedia to test my compiler.
28 Bytes! Unbelievable! It weights less than it's source!
Quote
#include <stdio.h>
int main()
{
puts("Hello World!");
}
int main()
{
puts("Hello World!");
}
Just cause I was curious, I compiled it with Borland TurboC 3.0.
6.93 KB (7,106 bytes). Geez.
Here's a Hello World for NASM -
Quote
section .text
org 0x100
mov ah, 0x9
mov dx, hello
int 0x21
mov ax, 0x4c00
int 0x21
section .data
hello: db 'Hello, world!', 13, 10, '$'
org 0x100
mov ah, 0x9
mov dx, hello
int 0x21
mov ax, 0x4c00
int 0x21
section .data
hello: db 'Hello, world!', 13, 10, '$'
28 Bytes! Unbelievable! It weights less than it's source!

There is no problem that cannot be solved by the use of high explosives.
#8
Posted 26 November 2010 - 09:08 AM
Yes, but that only works in real mode. Try running that from inside Windows or Linux.
sudo rm -rf /
#9
Posted 26 November 2010 - 09:23 AM
You mean pasting it in notepad and saving as foo.exe?
Yeah, I tried it. It gave me an error, something about illegal actions.
Yeah, I tried it. It gave me an error, something about illegal actions.

There is no problem that cannot be solved by the use of high explosives.
#10
Posted 26 November 2010 - 10:14 AM
You can't just write code in any language you choose, save it with a .EXE extension and expect it to execute. You have to compile it first into a format the operating system understands. For example, under Linux:
This gets you an object file (in ELF format) that you still have to link to the runtime system:
Now you can run myprogram. I can tell you right now, though, that your program as written won't link. The C runtime system expects a function called main to be defined, so you're going to have to rewrite your code like this:
Perform the above steps for compiling and linking, run it in the terminal, and expect a segfault. You cant use BIOS interrupts in protected mode on any operating system. Plus, you don't have a ret instruction to return to the C runtime system so the operating system is going to try and continue executing whatever comes in memory after your code, which is unpredictable. This, on the other hand, makes the proper system calls and will work on Linux:
Compilation/Linking:
That comes out to 5508 bytes on my system (32-bit Ubuntu), though I know I screwed up the optimization.
EDIT: I know how I can strip out the C runtime library, which gets it down to 480 bytes, but it segfaults at the end. You need to make a few changes to the code, but I'm not going to post it until I get rid of the segfault.
nasm -f elf -Wall -Werror -o mycode.o mycode.obj
This gets you an object file (in ELF format) that you still have to link to the runtime system:
gcc -o myprogram mycode.o
Now you can run myprogram. I can tell you right now, though, that your program as written won't link. The C runtime system expects a function called main to be defined, so you're going to have to rewrite your code like this:
; let the C runtime system see the main function global main section .text main: mov ah, 0x9 mov edx, hello int 21h mov ax, 0x4c00 int 21h section .data hello: db "Hello, World!"
Perform the above steps for compiling and linking, run it in the terminal, and expect a segfault. You cant use BIOS interrupts in protected mode on any operating system. Plus, you don't have a ret instruction to return to the C runtime system so the operating system is going to try and continue executing whatever comes in memory after your code, which is unpredictable. This, on the other hand, makes the proper system calls and will work on Linux:
global main section .text main: ; have to save EBX, EBP, ESI, EDI by convention push ebx ; make a call to write(). mov eax, 4 ; function 4 mov ebx, 1 ; handle to write to (stdout) mov ecx, hello ; buffer to write from mov edx, 14 ; number of bytes to write int 0x80 ; syscall interrupt pop ebx ret section .data hello: db "Hello, World!", 0x0a
Compilation/Linking:
nasm -felf -O3 -Wall -Werror -o test.o test.asm gcc -s -O3 -o test test.o
That comes out to 5508 bytes on my system (32-bit Ubuntu), though I know I screwed up the optimization.
EDIT: I know how I can strip out the C runtime library, which gets it down to 480 bytes, but it segfaults at the end. You need to make a few changes to the code, but I'm not going to post it until I get rid of the segfault.
sudo rm -rf /
#11
Posted 26 November 2010 - 11:14 AM
I was sure it won't run just cause I saved it as an exe, I was just curious what would happen.
Ehh... You just confused me. The program compiled/linked fine, does Assembly compile anyway?
I saved it as "Hello World.asm" under Windows XP, and used nasm.exe to compile it - "nasm "Hello World.asm" -o hi.exe". Of course, Linux's code is different.
Well, I'll try it soon on Debian as that's the only one I have here(other than Windows 7).
+rep, you deserve it.
Ehh... You just confused me. The program compiled/linked fine, does Assembly compile anyway?
I saved it as "Hello World.asm" under Windows XP, and used nasm.exe to compile it - "nasm "Hello World.asm" -o hi.exe". Of course, Linux's code is different.
Well, I'll try it soon on Debian as that's the only one I have here(other than Windows 7).
+rep, you deserve it.

There is no problem that cannot be solved by the use of high explosives.
#12
Posted 26 November 2010 - 11:41 AM
nasm just compiles, you need something else to link it. I don't know what it is on Windows, as I've never bothered writing ASM for it. (And thanks for the rep.)
sudo rm -rf /
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









