Re: Seg fault with hla 1.99 on Fedora 8 linux



Frank Kotler wrote:


Start with something simple... Linux only. We can add ExitProcess and
WriteFile later...

Best,
Frank

; nasm -f elf hwint.asm
; ld -o hwint hwint.o


Couldn't resist and had to convert your example to a more readable NASM
syntax. It's still not what I would call an usable syntax for writing
programs, but anything is better than Intel syntax:


;===========================================================================
; nasm -O99 -f bin -o hwint hwint.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: move.l hiya,r2
move.l hiya_len,r1
bsr.l write_stdout

move.l ans,r2
move.l ans_len,r1
bsr.l write_stdout

move.l [InitDemo],r0
bsr.l showeaxd

bsr.l newline
eor.l r0,r0 ; claim "no error".

exit: move.l r0,r3 ; error/return code in ebx (bl, actually)
move.l 1,r0 ; __NR_exit
trap $80


showeaxd:
movem.l r0-r7,-[sp] ; save caller's regs

sub.l $10,r7 ; make buffer on stack
lea.l [r7+$10],r2 ; start at "end" of buffer
move.l 10,r3 ; for decimal, divide by 10
eor.l r5,r5 ; length counter

.top: dec.l r2 ; work towards "front" of buffer
eor.l r1,r1 ; "div" works with edx:eax!
divu.l r3,r1|r0 ; quotient in eax, remainder in edx
add.b '0',r1 ; convert number to ascii char
move.b r1,[r2.l] ; store it
inc.l r5 ; count it
or.l r0,r0 ; quotient zero?
bne.b .top ; do more

move.l r5,r1 ; length in edx
bsr.l write_stdout ; print it

add.l $10,r7 ; free the buffer

movem.l [sp]+,r0-r7 ; restore caller's regs
rts.l

newline:movem.l r0-r7,-[sp]
moveq.l 10,-[sp] ; linefeed
move.l r7,r2 ; stack is the buffer
move.l 1,r1 ; just one
bsr.l write_stdout
addq.l 4,r7 ; free buffer
movem.l [sp]+,r0-r7
rts.l

write_stdout:
move.l 1,r3 ; STDOUT
move.l 4,r0 ; __NR_write
trap $80
rts.l

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

;--------------------------- constant data ---------------------------------
hiya: dc.b "Hello, World of (real) Assembly Language!", 10
hiya_len equ $-hiya

ans: dc.b "InitDemo's value is "
ans_len equ $-ans

InitDemo: dc.l 5
;---------------------------------------------------------------------------

align 4
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 ------------------------------

;---------------------------------------------------------------------------

idat_memsz equ $-$$
bss_addr equ data_addr+ ($-$$)
section .bss vstart=bss_addr

;--------------------------- uninitialized data ----------------------------

;---------------------------------------------------------------------------

udat_memsz equ $-$$
data_memsz equ idat_memsz + udat_memsz
data_filez equ idat_memsz
;===========================================================================

.



Relevant Pages

  • 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: which book to start with...?
    ... linux and i dont have windows. ... but your script doesnt look like nasm like given in Duntemann's book. ... orig equ $08048000 ... trap $80 ...
    (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)
  • Re: Nasm Error
    ... Nasm uses only a small subset that cares about OS - open, read, write, ... int 80h ... ORIGIN equ 8048000h ...
    (alt.lang.asm)