Re: Seg fault with hla 1.99 on Fedora 8 linux
- From: Herbert Kleebauer <spamtrap@xxxxxxxxxx>
- Date: Fri, 29 Feb 2008 14:25:43 +0100
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
;===========================================================================
.
- References:
- Seg fault with hla 1.99 on Fedora 8 linux
- From: DaveR
- Re: Seg fault with hla 1.99 on Fedora 8 linux
- From: Frank Kotler
- Re: Seg fault with hla 1.99 on Fedora 8 linux
- From: nbaker2328
- Re: Seg fault with hla 1.99 on Fedora 8 linux
- From: DaveR
- Re: Seg fault with hla 1.99 on Fedora 8 linux
- From: nbaker2328
- Re: Seg fault with hla 1.99 on Fedora 8 linux
- From: Frank Kotler
- Re: Seg fault with hla 1.99 on Fedora 8 linux
- From: nbaker2328
- Re: Seg fault with hla 1.99 on Fedora 8 linux
- From: Frank Kotler
- Seg fault with hla 1.99 on Fedora 8 linux
- Prev by Date: Re: Jumping into middle of instruction
- Next by Date: Re: Jumping into middle of instruction
- Previous by thread: Re: Seg fault with hla 1.99 on Fedora 8 linux
- Next by thread: Re: spim-like x86 simulator
- Index(es):
Relevant Pages
|