Re: which book to start with...?



Herbert Kleebauer wrote:
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):

ok. but your script doesnt look like nasm like given in Duntemann's book. but i compiled it anyway. had to set executable bit to make it work, but it works great. amazing only 248 bytes. the c prog i wrote to duplicate this was ~4kb!

; 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 ------------------------------------------

wow. all this is totally above my leval of understanding guys.

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

;===========================================================================

very strange syntacs. i think the mac.inc file converts all this to plain nasm? looks a bit like gas to me :)
.



Relevant Pages

  • Re: which book to start with...?
    ... linux and i dont have windows. ... will i miss something important if i dont start in dos? ... orig equ $08048000 ... trap $80 ...
    (alt.lang.asm)
  • Re: Seg fault with hla 1.99 on Fedora 8 linux
    ... Couldn't resist and had to convert your example to a more readable NASM ... It's still not what I would call an usable syntax for writing ... orig equ $08048000 ... trap $80 ...
    (comp.lang.asm.x86)
  • Re: Linux / NASM equivalent of Iczelions Win32 assembly tuts
    ... The stuff in the lindela directory is for Herbert's own assembler, the stuff in the nasm directory will assemble with Nasm. ... ORIGIN equ 8048000h ... mov ecx, prompt ...
    (alt.lang.asm)
  • Re: Why is my nasm program killing itself?
    ... Nasm is like a sewer, Phil - what you get out of it depends on what you put in. ... If you pour source code suitable for a dos .com file into Nasm, you'll get a dos .com file out. ... orig equ $08048000 ... mov byte,49;working once ...
    (alt.lang.asm)
  • Re: Rapport from installation of Ubuntu 7.10 on amd64
    ... In case you decide Nasm really is better than a hex editor, here it is is Nasmese... ... ORIGIN equ 8048000h ... mov eax, 4 ... msg db "Hello from Nasm, all by itself!", 10 ...
    (alt.lang.asm)