Re: which book to start with...?
- From: Herbert Kleebauer <klee@xxxxxxxxx>
- Date: Tue, 04 Dec 2007 09:45:10 +0100
naunetr wrote:
just dl'ed Dr. Paul Carter's tutorial (http://drpaulcarter.com/pcasm/)
and also PGU from (http://savannah.nongnu.org/projects/pgubook/). i also
borrowed "Assembly langauge step-by-step" by Jeff Dunteman from library.
so which one does the group experts reccomend to start with? my os is
linux and i dont have windows. is it necessary to start with dos as many
books say? then i'll have to use DosEmu+FreeDOS. is that okay? or can i
go with linux? will i miss something important if i dont start in dos?
also which is reccomanded..nasm or gas?
If you do it the "simple" way, assembly programming in Linux is as
nearly as simple as in DOS. Start with simple console applications
(a simple getc and putc to read/write from stdin/stdout is sufficient
for a start) and include the elf header as data block into the source
(this way you need no linker, NASM directly generates the executable
binary). Here a simple NASM example which converts DOS files (<CR><LF>)
to Unix files (<LF> only):
; nasm -O99 -f bin -o d2u d2u.asm
%include "mac.inc" ; ftp://137.193.64.130/pub/assembler/xlinux.zip
;===========================================================================
seg 32
orig equ $08048000
code_addr equ orig
code_offset equ 0
section .text vstart=code_addr
;--------------------------- ELF header -----------------------------------
dc.l $464c457f,$00010101,0,0,$00030002,1,main,$34,0,0,$00200034,2,0
dc.l 1,code_offset,code_addr,code_addr,code_filez,code_memsz,5,4096
dc.l 1,data_offset,data_addr,data_addr,data_filez,data_memsz,6,4096
;--------------------------- code ------------------------------------------
main:
.10: bsr.l getc
cmp.l -1,r0
beq.b .20
cmp.b 13,r0
beq.b .10
bsr.l putc
br.b .10
.20: move.l 0,r3 ; return code
move.l 1,r0 ; exit
trap $80
getc: movem.l r0-r7,-[sp]
move.l 0,r3 ; stdin
move.l buf,r2
move.l 1,r1 ; 1 byte
move.l 3,r0 ; read
trap $80
tst.l r0,r0
bmi.b .10
movem.l [sp]+,r0-r7
beq.b .20
movu.bl [buf],r0
rts.l
.20: orq.l -1,r0
rts.l
.10: orq.l -1,r3 ; return code
move.l 1,r0 ; exit
trap $80
putc: movem.l r0-r7,-[sp]
move.l 1,r3 ; stdout
move.l buf,r2
move.b r0,[r2.l]
move.l 1,r1 ; 1 byte
move.l 4,r0 ; write
trap $80
cmpq.l 1,r0
bne.b .10
movem.l [sp]+,r0-r7
rts.l
.10: orq.l -1,r3 ; return code
move.l 1,r0 ; exit
trap $80
;--------------------------- constant data ---------------------------------
; insert here any constant data you need in your program
;---------------------------------------------------------------------------
align 4, db 0
code_memsz equ $-$$
code_filez equ code_memsz
data_addr equ (orig+code_memsz+4095)/4096*4096 + (code_filez % 4096)
data_offset equ code_filez
section .data vstart=data_addr
;--------------------------- initialized data ------------------------------
; insert here any initialized data you need in your program
;---------------------------------------------------------------------------
idat_memsz equ $-$$
bss_addr equ data_addr+ ($-$$)
section .bss vstart=bss_addr
;--------------------------- uninitialized data ----------------------------
; insert here space for any uninitialized data you need in your program
buf: blk.b 4
;---------------------------------------------------------------------------
udat_memsz equ $-$$
data_memsz equ idat_memsz + udat_memsz
data_filez equ idat_memsz
;===========================================================================
.
- Follow-Ups:
- Re: which book to start with...?
- From: naunetr
- Re: which book to start with...?
- From: Frank Kotler
- Re: which book to start with...?
- From: santosh
- Re: which book to start with...?
- References:
- which book to start with...?
- From: naunetr
- which book to start with...?
- Prev by Date: Re: Sudoku
- Next by Date: Re: which book to start with...?
- Previous by thread: which book to start with...?
- Next by thread: Re: which book to start with...?
- Index(es):
Relevant Pages
|