From: beppu AT rigel DOT oac DOT uci DOT edu (John Beppu) Newsgroups: comp.os.msdos.djgpp Subject: NASM Propaganda Date: 15 Apr 1997 10:32:01 GMT Organization: University of California, Irvine Lines: 324 Message-ID: <5ivlf1$eif@news.service.uci.edu> NNTP-Posting-Host: rigel.oac.uci.edu To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp [NASM Propaganda] If you would like to | +-- use assembly under x86 Linux +-- use assembly with DJGPP +-- assemble MMX instructions +-- assemble PPro instructions +-- be able to use an x86 assembler on a non-x86 platform +-- output various object file formats such as | +-- bin +-- a.out +-- coff +-- elf +-- as86 +-- obj +-- win32 +-- rdf and are willing to pay 0 dollar$/pounds/en/etc. for such an assembler, NASM might be for you. If you already know TASM or MASM syntax, then moving to NASM will not be hard. If you are not comfortable with the AT&T assembly syntax, now you have an alternative. If you are afraid that your current assembler will not keep up with current processors, NASM comes with complete source so adding support for new instructions should not be /too/ difficult. [The Shortcomings] At the moment, NASM lacks | +-- macro support | | | +-- use a preprocessor like "cpp" or "m4" instead | +-- an easy way to align data | +-- hand-align or try the kludge mentioned in docs So, if you have been spoiled by macros (Randy Hyde ;-), or are extremely picky about data alignment, NASM may disappoint you. However, these shortcomings can be overcome, and future releases of NASM will probably address these issues. [In Conclusion] I ask that anyone who hasn't given NASM a chance to please do so. NASM is a very usable assembler. NASM binaries are small, so please keep it around even if you don't want to use it. NASM is another fine product from the UK. ftp://sunsite.unc.edu/pub/Linux/devel/lang/assemblers/nasm-0.94.tar.gz ftp://wcarchive.cdrom.com/pub/simtelnet/msdos/asmutl/nasm093s.zip [Peace Offering] [note] (I was going to cross-post at first, but the thought of Nudds polluting comp.os.msdos.djgpp made me reconsider.) I assume most of you comp.lang.asm.x86 folk still use DOS, so here's a little .com file you can test NASM out with. If you've got a (286 and a VGA) or better, and if you still use text-mode in DOS, you don't have to use the same, old, boring colors anymore. (yay.) This will also work with the Win95 dos shell. I'm a Linux user, but I must give respect to the people at Microsoft responsible for the dos shell, because they did a great job. I was surprised to see the EGA and VGA port accesses being caught and emulated within the dos shell. (When will DOSEMU be able to do this?! ;-) If you don't have "cpp", just get rid of all the C/C++ styled comments. I didn't use any #define statements, because I was a bit worried about the availability of "cpp". I didn't want people to be bothered to get the DJGPP package which contains the DOS port of "cpp". --8<-Makefile----------------------------------------------------------------- all : setpal.com setpal.com : setpal.s nasm -o setpal.com setpal.s setpal.s : setpal.asm cpp -P setpal.asm setpal.s --8<-setpal.asm--------------------------------------------------------------- [bits 16] [section .text] [org 100h] coder equ beppu // startUP xor ax,ax mov bp,argv mov [argv+7],ax ; setup for .length_check mov di,arg_buffer mov bx,000Dh mov cx,63 call _clP_save push ds pop es /* unmodular Philip-styled x86 asm (forgive me) usage: setpal 000f021f -+-r-g-b | | | + ( blue ) -+ | | +-- ( green ) | hexadecimal, | +---- ( red ) | please (no upper case) +------ ( palette entry ) -+ %% :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ _setpal: // Only one parameter desired. mov di,parser_table cmp cx,byte 1 mov ax,0ffffh jne near .end // Generate parser table. mov cx,128 mov bx,di xor dx,dx xor bp,bp rep stosw mov [bx+30h],bp ; 0,1 mov si,[argv] mov [bx+32h],bp ; 2,3 mov [bx+34h],bp ; 4,5 mov [bx+36h],bp ; 6,7 mov [bx+38h],bp ; 8,9 mov ax,[si+7] mov [bx+61h],dl ; a, mov [bx+62h],bp ; b,c cmp ah,1 mov [bx+64h],bp ; d,e mov [bx+66h],dl ; f sbb bp,bp // Parse parameter for validity // There must be exactly 8 characters within // the subset of { '0'..'9' && 'a'..'b' | .length_check: xor bx,bx and ax,bp jz near .end mov di,parser_table mov cx,8 xor ax,ax .validity_check: mov bl,[si] inc si mov dl,[bx+di] or ax,dx dec cx jnz .validity_check mov dx,0202h mov cx,0100h mov bx,parser_table test ax,ax jnz near .end // Turn parser_table into a conversion table // using poor man's MMX mov [bx+30h],cx ; 0,1 add cx,dx mov [bx+32h],cx ; 2,3 add cx,dx mov [bx+34h],cx ; 4,5 add cx,dx mov [bx+36h],cx ; 6,7 add cx,dx mov [bx+38h],cx ; 8,9 add cx,dx mov [bx+61h],cl ; a add cx,0101h mov [bx+62h],cx ; b,c add cx,dx mov [bx+64h],cx ; d,e inc ch mov [bx+66h],ch ; f // Convert parameter ; si == argv[1] mov si,[argv] sub sp,byte 4 ; a stackframe? mov di,bx mov bp,sp xor bx,bx xor ax,ax mov cx,4 .convert mov bl,[si] mov al,[bx+di] sal al,4 mov bl,[si+1] add si,byte 2 mov dl,[bx+di] or al,dl mov [bp],al inc bp dec cx jnz .convert mov bp,sp ; indeed. a stackframe. // Set palette mov dx,3c8h mov al,[bp] lea si,[bp+1] mov cx,3 out dx,al inc dx rep outsb add sp,byte 4 ; bye-bye, stackframe. .end: retn /* Proc clP_save far (8086+,DOS,realmode) :::::::::::::::::::::::::::::::::: IN: OUT: DS : seg Program Segment Prefix CX : # of parameters ES : seg of buffers DI : offset parameter_buffer | relative BP : offset offset_buffer | to ES CX : (len.b(param_b) - 1) BL : (len.w(offset_b)) offset param_b : filled BH : string termination byte offset offset_b : filled registers : ax bx cx dx di si bp (used) %% :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ _clP_save: cld mov si,80h ; # of chars on command-line mov al,[si] inc si cmp al,cl jge .noxchg cbw mov cx,ax ; looking for smaller one .noxchg: jcxz .empty mov al,20h mov ah,bh xor bh,bh mov dx,cx ; save final CX for later push di rep movsb ; copy eVerything pop di ;+---- mov cx,bx .werk: push cx mov cx,dx repe scasb ; while space dec di mov [es:bp],di ; set offset inc cx add bp,byte 2 repne scasb ; while NOT space jcxz .out mov [es:di - 1],ah mov dx,cx pop cx loop .werk ;+---- .out: mov [es:di],ah pop cx dec cx sub cx,bx neg cx ret .empty: xor cx,cx retn [section .bss] argc resw 1 argv resw 15 arg_buffer resb 64 parser_table resb 256 -- beppu AT uci DOT edu .............................................................