January 29th, 2002, 12:45 PM
linux vs assembly
i just wanna learn assembly.so does linux provide any assembler with it.i use RH 7.1.Help plz.
January 29th, 2002, 12:49 PM
depends if u installed it...
else get one..
there are a lot of assemblers 4 linux
ASCII stupid question, get a stupid ANSI.
When in Russia, pet a PETSCII.
Get your ass over to SLAYRadio
the best station for C64 Remixes !
January 29th, 2002, 05:55 PM
NASM is probably the most popular
get it here - www.web-sites.co.uk/nasm/
January 31st, 2002, 01:31 AM
Linux does have/provide support of assembly programming.
'gas' is generic provided assembler. It uses AT&T syntax
'nasm' also works for RH7.1 and it uses Intel syntax
both of these applications are on the linux distribution
Here is an example of the two forms to show the same functionality
example is taken from Assembly Language Step-by-Step by J.Duntemann
AT&T || Intel
movl -4(%ebx), %eax || mov dword eax,[ebx-4]
movb 28(%ebx,%edi), %eax || mov byte eax,[ebx+edi+28]
IMO the Intel is easier to read.
There is a high level kind of assembler programming and a lower
level, kernel mode assembler. The higher level is a hybrid of
C and assembly, (CASM). The lower form is using kernel sys calls
via interupt 80h (int 80h).
J.Duntemann's book is very basic introduction level programming and
he uses the CASM style of programmming. Just forgetting stack frame
creation and destruction for a minute, here is how you would write
a text message to the standard output (1) i.e. screen
extern puts ; clib function
global main ; entry point for linker
; ; create stack frame code
push dword message ; push address of msg on stack
call puts ; function call
add esp, 4 ; realign stack
; ; destroy stack frame code
message: db "hello",0x0A,0x00
Now a more advanced style (not covered by Dunteman) int 80h type
goes like this.
PZ's simple int80h demo
read a file and output it to standard output i.e the screen
nasm -f elf read_write01.asm
gcc read_write01.o -o demo01
------------------ cut from here ---------------------------------
O_RDONLY EQU 0
sys_close EQU 1
sys_read EQU 3
sys_write EQU 4
sys_open EQU 5
std_oput EQU 1
_start: mov ebp,esp
mov eax,[ebp] ; argc
mov [argc],eax ; copy the address value to variable
mov eax,[ebp] ; argv0
mov eax,[ebp] ; argv1
Openit: mov eax,sys_open ; open
mov ebx,[argv1] ; path in argv of command line
mov ecx, O_RDONLY ; read only
mov edx, 0 ; permission mode not relevant to read
mov[filedesc],eax ; save the returned file descriptor
printfd: mov eax,sys_write ; write
mov ebx,std_oput ; standard output
mov ecx,filedesc ; print the file descriptor
mov edx,4 ; it is 4 bytes long
readit: mov eax,sys_read ; read
mov ebx,[filedesc] ; our file, just opened
mov ecx,storage ; scratchpad area
printit: mov eax,sys_write ; write
mov ebx,std_oput ; standard output
mov ecx,storage ; output what was read in from the file
finish: mov eax,sys_close
argc RESD 1
argv0 RESD 1
argv1 RESD 1
filedesc RESD 1
storage RESB 1024
----------------------- finish cut -------------------------
You can also mix and match CASM with int80h, which is sometimes easier
if you are a bit lazy.
Another thing that is permisable is to use inline assembler embedded into
C code. Infact this is how the Linux kernel is constructed.
static inline void set_in_cr4(unsigned long mask)
mmu_cr4_features |= mask;
: : "irg" (mask)
really nice looking this inline AT&T assmbler with C, ey?
Next lesson how to grab ring-0 with buffer overflows *lol*
p.s. remember how when kids advance from baby languages like BASIC
to Pascal, Fortran, C/C++ etc they are told to forget all about
GOTO cus now we are learning structured programming, well
once you get back to serious system level programming you
start using GOTO again. *grin* The linux kernel consists of
about 1 in every 80 lines has a GOTO.
C-ASM inline is dirty powerful programming, who cares if we