Re: Nasm Error



Wolfgang Kern wrote:

....
But I downloaded the C-source and Frank's C-style is somehow good
readable [ASM-influenced?] for me, so I can see how/why/when NASM
will work.

Not mine. But the folks who coded it are obviously aware of asm, and
know what "just call printf" is actually asking to do, so I'd expect a
fairly "sane" coding style. They know better than to "throw library
routines up into the tree until the correct answer falls out".

So this will help me to figure out how L'unix should be treated ...

Most of Nasm is designed to be OS-ignorant. The output "drivers",
outelf32.c and outelf64.c might be some help.

Perhaps I once write a C-compiler for KESYS, or just a smart script
converter. I'd estimate it could produce final files with at least
100:1 source/code-size ratio without loosing execution speed.

Unless I'm mistaken, the library is a bigger deal than the compiler.
Nasm uses only a small subset that cares about OS - open, read, write,
close, malloc, free. If you could arrange these to do "KESYS_open", etc.
you'd be halfway there. Nasm uses libc for strthis and strthat all over
the place, of course, but existing code ought to run on any OS - or it
can be implemented in asm.

But why? You seem to be doing okay with the tools you've got. If you
have reason to write/port a C compiler - and the little matter of the
library - then you get Nasm "for free", pretty much. If not, Nasm might
not be the best place to start.

To get a "L'unix" (the system run by L'unitics) subsystem going, start
simple:

mov eax, 1
int 80h

That ought to return to the KESYS "shell", I suppose - whatever you do.
Then:

mov ebx, 42
mov eax, 1
int 80h

I don't know what, if any, attention KESYS pays to "exit codes" or
"errorlevels", but... do what you do.

C can call it as "exit(42)", and get the same code as the int 80h with
eax=1 executes. eax=2 is "fork"... etc. I suspect there will be a lot of syscalls that just "don't apply", though.

I suppose you'll want a loader. Maybe you can figure out something by looking at outelf32.c, but it produces linkable object code. Maybe looking at programs done "Herbert style" with the elf header laid out would be simpler. Here's a fairly "minimal" example...

Best,
Frank

[map all hw.map]
;===========================================================================
bits 32
ORIGIN equ 8048000h
org ORIGIN
section .text
code_offset equ 0
code_addr:
;--------------------------- ELF header -----------------------------------
dd $464c457f,$00010101,0,0,$00030002,1,main,$34,0,0,$00200034,2,0
dd 1,code_offset,code_addr,code_addr,code_filez,code_memsz,5,4096
dd 1,data_offset,data_addr,data_addr,data_filez,data_memsz,6,4096
;--------------------------- code ------------------------------------------
main:
mov eax, 4
mov ebx, 1
mov ecx, msg
mov edx, msg_len
int 80h

mov eax, 1
int 80h

;--------------------------- constant data ---------------------------------
; (note that we're in .text, not .rdata)
align 4

; we have none

;---------------------------------------------------------------------------
align 4
code_memsz equ $ - $$
code_filez equ code_memsz
data_addr equ (ORIGIN+code_memsz+4095)/4096*4096 + (code_filez % 4096)
data_offset equ code_filez
section .data vstart=data_addr
;--------------------------- initialized data ------------------------------

msg db "Hello from Nasm, all by itself!", 10
msg_len equ $ - msg


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

; we have none

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



Relevant Pages

  • Re: Nasm Error
    ... existing code ought to run on any OS - or it can be implemented in asm. ... int 80h ... ORIGIN equ 8048000h ...
    (alt.lang.asm)
  • A new assembly language
    ... WM_CLOSE equ 10h; EM_SETSEL equ 0b1h; ... push DlgProc ... mov eax, @hdlg ... mov esi, @hdlg ...
    (alt.lang.asm)
  • A window problem
    ... WM_INITDIALOG equ 0110h ... push DProc ... mov eax, @hdlg ...
    (alt.lang.asm)
  • Re: questions from a newbie
    ... Nobody has given me reasons to use as, nasm, or others and why. ... O_DIRECTORY equ 00200000Q ... mov ebx,texmfdir ... int 80h ...
    (alt.lang.asm)
  • 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)