flat assembler
Message board for the users of flat assembler.

flat assembler > DOS > TEXTMODE code snipplets for newbies

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
I think this knows -all you can specify the color x and y position to write to,
it is very fast ! uses a 0 terminated string

Code:
writestring80x25: ; DX = address of string bl=x bh=y cl=color , 0 terminated string !
push ds
push si
push es
push di
push $b800
pop es
mov si,dx
mov ax,80
mul bh
xor bh,bh
add ax,bx
shl ax,1
mov di,ax
mov ah,cl
again:
lodsb
or al,al
jz done
stosw
jmp again
done:
pop di
pop es
pop si
pop ds
ret
    


MATRIX


Last edited by Matrix on 23 Oct 2004, 15:23; edited 1 time in total
Post 04 Sep 2004, 22:02
View user's profile Send private message Visit poster's website Reply with quote
Bitdog



Joined: 18 Jan 2004
Posts: 97
Yep, quick, but quicker still remains.....
the programmer doesn't have to make a PROC that computes the screen position of X/Y, cause he can do it himself as he writes the program.
the old idea of ROW x SCREEN-WIDTH + COLUMN = SCREEN OFFSET
isn't required, just do the SCREEN OFFSET in your code and it's quicker
at run time. AND if you know the size of the data (and you always do some how)
MOV CX,size?
REPZ MOVSW
is all you need to do to get the job done. (load DS:SI & ES:DI first of course.)
Once this is the rule, it's easier/quicker to just write the MOVSW code in
a macro and thus avoid the CALL, & the MATH.
A few extra bytes in ones code adds up to nothing of importance,
as long as you're using fast_ass_asm w/Fasm I've always said......Wink
I try to live by: KISS = Keep It Simple Stupid.
Cuz it werks.
Bitdog
Post 05 Sep 2004, 05:19
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Bitdog wrote:
Yep, quick, but quicker still remains.....
the programmer doesn't have to make a PROC that computes the screen position of X/Y, cause he can do it himself as he writes the program.
the old idea of ROW x SCREEN-WIDTH + COLUMN = SCREEN OFFSET
isn't required, just do the SCREEN OFFSET in your code and it's quicker
at run time. AND if you know the size of the data (and you always do some how)
MOV CX,size?
REPZ MOVSW
is all you need to do to get the job done. (load DS:SI & ES:DI first of course.)
Once this is the rule, it's easier/quicker to just write the MOVSW code in
a macro and thus avoid the CALL, & the MATH.
A few extra bytes in ones code adds up to nothing of importance,
as long as you're using fast_ass_asm w/Fasm I've always said......Wink
I try to live by: KISS = Keep It Simple Stupid.
Cuz it werks.
Bitdog


Hy there dear bitdog,
i have a short comment for your comment, there might be a faster way of writing a text string to 80x25 text mode, but this is a few hundred times faster way than dos output, and is using the color.
if u know a better way of writing a 0 terminated string to 80x25 text mode with colors, please send it to me. however i know some too but they are only faster for longer texts, and if u want incredible speeds, u use an offscreen buffer and just fetch it to video ram directly.
MATRIX
Post 05 Sep 2004, 05:39
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
after clearing:
Code:
writestring80x25: ; DX = address of string bl=x bh=y cl=color , 0 terminated string !
push es
push $b800
pop es
mov si,dx
mov ax,80
mul bh
xor bh,bh
add ax,bx
shl ax,1
mov di,ax
mov ah,cl
again:
lodsb
cmp al,0
je ext2
stosw
jmp again
ext2:
pop es
ret
    


MATRIX


Last edited by Matrix on 23 Oct 2004, 15:24; edited 4 times in total
Post 08 Sep 2004, 11:12
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Its not a big thing but you can do big things with them Smile
these took about 1.5 mS on my ˇ933 Celeron with AGP Tnt2
Code:
scroll80x25down: ; CX = lines to scroll ( must be valid )
push es
push ds
std
mov ax,$b800
mov ds,ax
mov es,ax
mov di,4000
mov ax,cx
shl ax,2
add ax,cx
shl ax,5
mov si,di
sub si,ax
mov dx,ax
mov ax,25
sub ax,cx
mov cx,ax
shl ax,2
add ax,cx
shl ax,3
xor ecx,ecx
mov cx,ax
inc cx
rep movsd
mov eax,$07200720
mov cx,dx
shr cx,2
rep stosd
cld
pop ds
pop es
ret

mesh80x25down: ; CX = lines to scroll ( must be valid )(don't clear top line)
push es
push ds
std
mov ax,$b800
mov ds,ax
mov es,ax
mov di,4000
mov ax,cx
shl ax,2
add ax,cx
shl ax,5
mov si,di
sub si,ax
mov ax,25
sub ax,cx
mov cx,ax
shl ax,2
add ax,cx
shl ax,3
xor ecx,ecx
mov cx,ax
inc cx
rep movsd
cld
pop ds
pop es
ret
    


MATRIX


Last edited by Matrix on 08 Sep 2004, 12:10; edited 2 times in total
Post 08 Sep 2004, 11:18
View user's profile Send private message Visit poster's website Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
matrix, please put code in [ code ] and [ /code ] tags (remove the spaces). It makes it much easier to read. Oh, and a few comments never hurt either... Smile
Post 08 Sep 2004, 12:00
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Here you are Smile

MATRIX
Post 08 Sep 2004, 12:08
View user's profile Send private message Visit poster's website Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
Thank you Smile
Post 08 Sep 2004, 12:51
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
After writing all that garbage to screen you might wanna clear the screen am i right? Smile
have any ideas how can this be done?
Code:
cls80x25t: ; clear the text screen really fast
push es
push $b800
pop es
xor eax,eax
mov di,ax
mov eax,$07200720
mov cx,1000
rep stosd
pop es
ret

sorry for this, i correct it

cls80x25t: ; clear the text screen really fast
push es
push $b800
pop es
xor di,di
mov eax,$07200720
mov cx,1000
rep stosd
pop es
ret

    


MATRIX


Last edited by Matrix on 18 Sep 2004, 20:52; edited 1 time in total
Post 08 Sep 2004, 16:47
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
The ultimate speed :
calculating the x and y

Code:
write80x25: ; DL = Char to write DH = Color bl=x bh=y , returns: AX = DX, DI = offset
push es
mov ax,$b800
mov es,ax

xor ax,ax
xchg al,bh   ;  mov ax,80
mov di,ax    ;  mul bh
shl di,2     ;  xor bh,bh
add di,ax    ;  add ax,bx
shl di,4     ;  shl ax,1
add di,bx    ;  mov di,ax
shl di,1

mov ax,dx
stosw
pop es
ret

writestring80x25: ; DX = address of string bl=x bh=y cl=color , 0 terminated string !
push es
mov ax,$b800
mov es,ax
mov si,dx

xor ax,ax
xchg al,bh   ;  mov ax,80
mov di,ax    ;  mul bh
shl di,2     ;  xor bh,bh
add di,ax    ;  add ax,bx
shl di,4     ;  shl ax,1
add di,bx    ;  mov di,ax
shl di,1

mov ah,cl
again:
lodsb
cmp al,0
je ext2
stosw
jmp again
ext2:
pop es
ret
    


MATRIX


Last edited by Matrix on 11 Sep 2004, 06:02; edited 1 time in total
Post 09 Sep 2004, 14:54
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Ever wanted to convert value to hex? Smile now here are my codes:

Code:
nibble2hex: ; converts 4 bit al to hex (1 nibbles) in al
and al,00001111b
cmp al,10
sbb al,69h
das
ret

byte2hex: ; converts byte al to hex (2 nibbles) in ax
mov ah,al
shr al,4
cmp al,10
sbb al,69h
das
xchg al,ah
and al,00001111b
cmp al,10
sbb al,69h
das
ret

word2hex: ; converts word ax to hex (4 nibbles) in eax , returns: bh=al
mov bh,al ; i don't like stack but if you need bh you can use push and pop
mov al,ah
shr al,4
cmp al,10
sbb al,69h
das
xchg al,ah
and al,00001111b
cmp al,10
sbb al,69h
das
shl eax,16
mov al,bh
mov ah,al
shr al,4
cmp al,10
sbb al,69h
das
xchg al,ah
and al,00001111b
cmp al,10
sbb al,69h
das
ret
    


MATRIX
Post 09 Sep 2004, 14:58
View user's profile Send private message Visit poster's website Reply with quote
neonz



Joined: 02 Aug 2003
Posts: 62
Location: Latvia
Why you need "push ds / ... / pop ds" if you don't change DS anywhere in your code?
Post 11 Sep 2004, 01:10
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
neonz wrote:
Why you need "push ds / ... / pop ds" if you don't change DS anywhere in your code?


it was a mistake, thanx
many ticks Smile

MATRIX
Post 11 Sep 2004, 06:01
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
i give you something to play with Smile

Code:

nibble2hex: ; converts 4 bit al to hex (1 nibbles) in al
and al,00001111b
cmp al,10
sbb al,69h
das
ret

byte2hex: ; converts byte al to hex (2 nibbles) in ax
mov ah,al
shr al,4
cmp al,10
sbb al,69h
das
xchg al,ah
and al,00001111b
cmp al,10
sbb al,69h
das
ret

word2hex: ; converts word ax to hex (4 nibbles) in eax , returns: bh=al
mov bh,al
mov al,ah
shr al,4
cmp al,10
sbb al,69h
das
xchg al,ah
and al,00001111b
cmp al,10
sbb al,69h
das
shl eax,16
mov al,bh
mov ah,al
shr al,4
cmp al,10
sbb al,69h
das
xchg al,ah
and al,00001111b
cmp al,10
sbb al,69h
das
ret

word2hexr: ; converts word ax to hex (4 nibbles) in eax
mov bx,ax
xor cx,cx
.roll1:
ror bx,8
.roll2:
xor cl,4
mov al,bh
ror al,cl
and al,00001111b
cmp al,10
sbb al,69h
das
xchg al,ah
or cl,cl
jnz .roll2
xchg al,ah
cmp ch,1
ja .skip1
shl eax,16
.skip1:
inc ch
cmp ch,2
jbe .roll1
ret                        

    


MATRIX
Post 11 Sep 2004, 06:06
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
about the comments :

i can't make comments as fast as i make a functions in assembly.
but for example i don't even need them Smile

MATRIX
Post 11 Sep 2004, 06:18
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
i used to by playing around with things like these:

Code:

writehexnibble80x25: ; DL (low) = 4 bit input bl=x bh=y ch=color ( writes 1 nibbles from input )
push es
mov ax,$b800
mov es,ax

xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1

mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
stosw
pop es
ret

writehexbyte80x25: ; DL = byte input bl=x bh=y ch=color ( writes 2 nibbles from input )
push es
mov ax,$b800
mov es,ax

xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1

mov al,dl
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
stosw
mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das
stosw
pop es
ret

writehexword80x25: ; DX = word input bl=x bh=y ch=color ( writes 4 nibbles from input )
push es
mov ax,$b800
mov es,ax
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1

mov al,dh
and al,00001111b
cmp al,10
sbb al,69h
das

mov ah,ch
shl eax,16

mov al,dh
shr al,4
cmp al,10
sbb al,69h
das

mov ah,ch
stosd

mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das

mov ah,ch
shl eax,16

mov al,dl
shr al,4
cmp al,10
sbb al,69h
das

mov ah,ch
stosd

pop es
ret

writehexwordspaced80x25: ; DX = word input bl=x bh=y ch=color ( writes 2+' '+2 nibbles from input )
push es
mov ax,$b800
mov es,ax
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1

mov al,dh
and al,00001111b
cmp al,10
sbb al,69h
das

mov ah,ch
shl eax,16

mov al,dh
shr al,4
cmp al,10
sbb al,69h
das

mov ah,ch
stosd

mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das

add di,2

mov ah,ch
shl eax,16

mov al,dl
shr al,4
cmp al,10
sbb al,69h
das

mov ah,ch
stosd

pop es
ret

writehexdword80x25U: ; EDX = dword input bl=x bh=y ch=color ( writes 8 nibbles from input )
push es         ; unrolled = speed optimized
mov ax,$b800
mov es,ax
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1

ror edx,16

mov al,dh
and al,00001111b
cmp al,10
sbb al,69h
das

mov ah,ch
shl eax,16

mov al,dh
shr al,4
cmp al,10
sbb al,69h
das

mov ah,ch
stosd

mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das

mov ah,ch
shl eax,16

mov al,dl
shr al,4
cmp al,10
sbb al,69h
das

mov ah,ch
stosd
ror edx,16

mov al,dh
and al,00001111b
cmp al,10
sbb al,69h
das

mov ah,ch
shl eax,16

mov al,dh
shr al,4
cmp al,10
sbb al,69h
das

mov ah,ch
stosd

mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das

mov ah,ch
shl eax,16

mov al,dl
shr al,4
cmp al,10
sbb al,69h
das

mov ah,ch
stosd

pop es
ret

writehexdword80x25R: ; EDX = dword input bl=x bh=y ch=color ( writes 8 nibbles from input )
push es         ; rolled 1 = speed and size optimized
mov ax,$b800
mov es,ax
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1

mov cl,2
.roll1:
ror edx,16
mov al,dh
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
shl eax,16
mov al,dh
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
stosd
mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
shl eax,16
mov al,dl
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
stosd
dec cl
or cl,cl
jnz .roll1
pop es
ret

writehexdword80x25R2: ; EDX = dword input bl=x bh=y ch=color ( writes 8 nibbles from input )
push es          ; rolled 2 = speed and double size optimized
mov ax,$b800
mov es,ax
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1

mov bh,2
.roll1:
ror edx,16
mov bl,2
.roll2:
ror dx,8

mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
shl eax,16
mov al,dl
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
stosd

dec bl
or bl,bl
jnz .roll2
dec bh
or bh,bh
jnz .roll1
pop es
ret

writehexdword80x25R3: ; EDX = dword input bl=x bh=y ch=color ( writes 8 nibbles from input )
push es         ; rolled 3 = triple rolled speed and double size optimized
mov ax,$b800    ;     uses : EAX BX CL
mov es,ax       ;  returns : BX=0, CH=4, Di=Di+8, EAX='dl cl dh cl', EDX, CH
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1

mov bh,2
.roll1:
ror edx,16
mov bl,2
.roll2:
ror dx,8
xor cl,cl
.roll3:
mov al,dl
ror al,cl
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
cmp cl,4
jae .skiproll
shl eax,16
.skiproll:
add cl,4
cmp cl,4
jbe .roll3
stosd
dec bl
or bl,bl
jnz .roll2
dec bh
or bh,bh
jnz .roll1
pop es
ret

writehexdword80x25R3M: ; EDX = dword input bl=x bh=y ch=color ( writes 8 nibbles from input )
push es          ;  rolled 3 = triple rolled triple size optimized ( KEEP IT SIMPLE STUPID ! )
push $b800       ;      uses : EAX BX CL
pop es           ;   returns : BX=0, CH=4, Di=Di+8, EAX='dl cl dh cl', EDX, CH
mov ax,80
mul bh
xor bh,bh
add ax,bx
shl ax,1
mov di,ax
mov bh,2
.roll1:
ror edx,16
mov bl,2
.roll2:
ror dx,8
xor cl,cl
.roll3:
mov al,dl
ror al,cl
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
cmp cl,4
jae .skiproll
shl eax,16
.skiproll:
add cl,4
cmp cl,4
jbe .roll3
stosd
dec bl
or bl,bl
jnz .roll2
dec bh
or bh,bh
jnz .roll1
pop es
ret


writehexdwordspaced80x25U: ; EDX = dword input bl=x bh=y ch=color ( writes 8 nibbles from input )
push es               ; unrolled = speed optimized  ( writes 2+' '+2+' '+2+' '+2+' ' nibbles from input )
mov ax,$b800
mov es,ax
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1

ror edx,16
mov al,dh
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
shl eax,16
mov al,dh
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
stosd
mov al,dl
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
shl eax,16
mov al,$20
mov ah,ch
stosd
mov al,$20
mov ah,ch
shl eax,16
mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
stosd
ror edx,16
mov al,dh
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
shl eax,16
mov al,dh
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
stosd
mov al,dl
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
shl eax,16
mov al,$20
mov ah,ch
stosd
mov al,$20
mov ah,ch
shl eax,16
mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
stosd
pop es
ret

writehexdwordspaced80x25R: ; EDX = dword input bl=x bh=y ch=color ( writes 8 nibbles from input )
push es               ;   rolled = size&speed optimized  ( writes 2+' '+2+' '+2+' '+2+' ' nibbles from input )
mov ax,$b800
mov es,ax
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1
mov cl,2
.roll1:
ror edx,16
mov al,dh
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
shl eax,16
mov al,dh
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
stosd
mov al,dl
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
shl eax,16
mov al,$20
mov ah,ch
stosd
mov al,$20
mov ah,ch
shl eax,16
mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
stosd
dec cl
or cl,cl
jnz .roll1
pop es
ret

writehexdwordspaced80x25M: ; EDX = dword input bl=x bh=y ch=color ( writes 8 nibbles from input )
push es               ;   rolled = size optimized  ( writes 2+' '+2+' '+2+' '+2+' ' nibbles from input )
push $b800
pop es
mov ax,80
mul bh
xor bh,bh
add ax,bx
shl ax,1
mov di,ax
mov cl,2
.roll1:
ror edx,16
mov al,dh
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
shl eax,16
mov al,dh
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
stosd
mov al,dl
shr al,4
cmp al,10
sbb al,69h
das
mov ah,ch
shl eax,16
mov al,$20
mov ah,ch
stosd
mov al,$20
mov ah,ch
shl eax,16
mov al,dl
and al,00001111b
cmp al,10
sbb al,69h
das
mov ah,ch
stosd
dec cl
or cl,cl
jnz .roll1
pop es
ret

now this writes decimal via bios:

bwritewordu: ; writes AX to screen @ x,y (at cursor)
mov bx,7    ; returns:  AX,CX,DX = undefined ; BX = 7
cmp ax,10000
jnb .down1
cmp ax,1000
jnb .down2
cmp ax,100
jnb .down3
cmp ax,10
jnb .down4
jmp .down5
.down1:
mov dx,0
mov cx,10000
div cx
add al,48
mov ah,0xE
int 10h
mov ax,dx
.down2:
mov dx,0
mov cx,1000
div cx
add al,48
mov ah,0xE
int 10h
mov ax,dx
.down3:
mov cl,100
div cl
mov dl,ah
add al,48
mov ah,0xE
int 10h
mov al,dl
mov ah,0
.down4:
mov cl,10
div cl
mov dl,ah
add al,48
mov ah,0xE
int 10h
mov al,dl
.down5:
add al,48
mov ah,0xE;
int 10h
ret

i almost forgot, with bios you must

bendline: ; ends the line ( adds y loc = 1 x loc = 0 )
mov bx,7 ; returns:  AX = 0xE0A ; BX = 7
mov ax,$E0D
int 10h
mov al,$A
int 10h
ret

bgotoxy: ; dl=x, dh=y ( 0,0 = upper left ) RETURNS:  AX,BX,DX = undefined.
mov ah,2
xor bh,bh
int 10h
ret       

you know what i mean

if you make them better you can post them to me.

    


Cool
ps .: There is your KEEP IT SIMPLE STUPID !!! BITDOG

MATRIX
Post 11 Sep 2004, 06:22
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Okey, lets write a double word to screen in decimal from EAX
this version doesn't use stack!
( curerntly this writes via bios)

Code:

bwritedword: ; writes EAX to screen @ x,y (at cursor)
                  ; returns:  EAX,ECX,EDX = undefined ; BX = 7
mov ecx,1000000000 ; if bx= 0 then writes in graphic mode
.sroll1:
cmp eax,ecx
jae .sskip2
.divide:
mov ebx,eax
mov eax,ecx
mov ecx,10
xor edx,edx
div ecx
mov ecx,eax
mov eax,ebx
 jecxz .sskip
  jmp .sroll1 ; remove leading zeroes
.rolldivide:
mov ebx,eax
mov eax,ecx
mov ecx,10
xor edx,edx
div ecx
mov ecx,eax
mov eax,ebx
 jecxz .extroll
.sskip2:
xor edx,edx
div ecx
.sskip:
add al,48
mov ah,0xE
mov bx,7
int 10h
mov eax,edx
 jecxz .extroll
  jmp .rolldivide
.extroll:
ret

    


MATRIX


Last edited by Matrix on 23 Oct 2004, 15:28; edited 1 time in total
Post 18 Sep 2004, 16:56
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
here's a stack stack procedure for you to display
numbers in any base (2-16) via bios:

Code:

putint: ; AX = number, BX = base
  push ax bx cx dx
  cmp bx,2 ; base can't be less than 2 Smile
  jge .start
  mov bx,10     ; using bx = 10 instead
  .start:
  xor cx,cx     ; cx = 0
  .new:
  xor dx,dx     ; dx = 0
  div bx        ; number / base
  push dx       ; push the remainder
  inc cx        ; increase the "digit-count"
  or ax,ax      ; if the quotient still is not 0, do it once more
  jnz .new
  .loop:
  pop ax        ; pop the remainder
cmp al,10
sbb al,69h
das
push bx
mov bx,15 ;mov bl,15 ;xor bh,bh
mov ah,$e
int 10h
pop bx
  loop .loop
  pop dx cx bx ax
ret

putlongint: ; EAX = number, EBX = base
  push eax ebx ecx edx
  cmp ebx,2 ; base can't be less than 2 Smile
  jge .start
  mov ebx,10     ; using bx = 10 instead
  .start:
  xor ecx,ecx     ; cx = 0
  .new:
  xor edx,edx     ; dx = 0
  div ebx        ; number / base
  push dx       ; push the remainder
  inc ecx        ; increase the "digit-count"
  or eax,eax      ; if the quotient still is not 0, do it once more
  jnz .new
  .loop:
  pop ax        ; pop the remainder
cmp al,10
sbb al,69h
das
push bx
mov bx,15 ;mov bl,15 ;xor bh,bh
mov ah,$e
int 10h
pop bx
  loop .loop
  pop edx ecx ebx eax
ret


    


ps.: i have constructed it from an article on this message board,
for your personal needs you may wanna modify it too.

if the article is still alive then here it is
http://board.flatassembler.net/topic.php?t=42

MATRIX
Post 18 Sep 2004, 20:28
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Hy all,
You can laugh on me now, but i have improved my code Smile

Code:
writehexnibbles80x25z: ; EDX = 32 bit input bl=x bh=y ch=color ( writes 8 nibbles from input )
push es                ; does not remove leading zeroes
mov ax,$b800
mov es,ax
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1
mov cl,8
.roll1:
rol edx,4
mov al,dl
and al,$f
cmp al,10
sbb al,69h
das
mov ah,ch
stosw
dec cl
;or cl,cl
jnz .roll1
pop es
ret

writehexnibbles80x25: ; EDX = 32 bit input bl=x bh=y ch=color ( writes 8 nibbles from input )
push es               ; removes leading zeroes
mov ax,$b800
mov es,ax
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1
mov cl,8
.roll1:
rol edx,4
mov al,dl
and al,$f
jnz .rollskip
dec cl
;or cl,cl
jnz .roll1
inc cl
.roll2:
rol edx,4
.rollskip:
mov al,dl
and al,$f
cmp al,10
sbb al,69h
das
mov ah,ch
stosw
dec cl
;or cl,cl
jnz .roll2
pop es
ret
    


MATRIX
Post 19 Sep 2004, 17:54
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
speedy code for converting to hex:

Code:
;Converts a 32 bit number to an 8-byte string, (MMX+)
;Notes: 14 cycles. Input: EAX; output:hex-format character string pointed to by [EDI].
Hex2Str32_MMX:
        bswap     eax
        movq      mm3,[sum1123]
        movq      mm4,[comp123]
        movq      mm2,[mask123]
        movq      mm5,mm3
        psubb     mm5,mm4
        movd      mm0,eax
        movq      mm1,mm0
        psrlq     mm0,4
        pand      mm0,mm2
        pand      mm1,mm2
        punpcklbw mm0,mm1
        movq      mm1,mm0
        pcmpgtb   mm0,mm4
        pand      mm0,mm5
        paddb     mm1,mm3
        paddb     mm1,mm0
        movq     [edi],mm1
        ret
sum1123: dq $3030303030303030
mask123: dq $0f0f0f0f0f0f0f0f
comp123: dq $0909090909090909
    
Post 12 Nov 2004, 22:01
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.