Board index » off-topic » help with asm

help with asm


2003-10-20 06:01:04 AM
off-topic4
Dear Friends
I has an asm code but is gpfing
The function i used properly on 16bits code, but now i need the same to work
on 32 bits
Bellow is original source (16 bit code )
IDEAL
WARN
EXTRN _hb_parc:FAR, _hb_parnd:FAR, _hb_retclen:FAR, _hb_retnd:FAR
SEGMENT _prog DWORD 'CODE'
ASSUME cs:_prog, ds:nothing, es:nothing
;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
;;
;; Syntax: string-10 := l_dtot( <number>)
;;
;; Purpose: Converts an IEEE 8 byte into an IEEE 10 byte real.
;;
;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
PUBLIC l_dtot
PROC l_dtot FAR
push bp
mov bp, sp
xor ax, ax ; Push a 0 TREAL onto the stack.
push ax
push ax
push ax
push ax
push ax
inc ax ; Get the address of our double.
push ax
call _hb_parnd
pop bx
mov bx, sp ; Base address of TREAL.
mov cx, 10 ; Setup return logic for _hb_retclen.
push cx
push ss
push bx
push ds ; Save what we mangle...
push si
push di
mov ds, dx ; Return from _hb_parnd is source.
mov si, ax
push ds ; Test for 0.
pop es
mov di, si
xor ax, ax
mov cx, 4
rep scasw
je @@skip
push ss ; Stack is destination.
pop es
mov di, bx
;;
;; This next step is kinda kludgy. The mantissa of an 8-IEEE is shifted
;; 4 bits from the 10-IEEE. But the assumed 1.0 of an 8-IEEE isn't in
;; the 10-IEEE. That means that we end up with a 3-bit shift and an
;; explicit 1 bit added (except for 0).
;;
mov cl, 5
xor ax, ax ; LSB will always be 0. First 3 bits
stosb ; of next nibble will also be 0.
REPT 6
lodsb
rol ax, 1
rol ax, 1
rol ax, 1
stosb
shl ah, cl
ENDM
lodsb ; Special processing for last byte to
rol ax, 1 ; keep the start of the mantissa out
rol ax, 1 ; of it.
rol ax, 1
rol ax, 1
stc
rcr al, 1
stosb
;;
;; We have the LS-nibble of the exponent in AH now. Load the rest
;; (including the sign), change the bias from 1023 (QUAD) to 16383
;; (TREAL), and store it all...
;;
lodsb
mov bh, al ; Save sign bit.
dec cl
shl ah, cl
rol ax, cl
and ah, 07h
add ax, 16383d - 1023d
and bh, 80h ; Move in sign.
or ah, bh
stosw
@@skip: pop di ; Restore mangled registers.
pop si
pop ds
call _hb_retclen ; Make our call and return.
mov sp, bp
pop bp
ret
ENDP
;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
;;
;; Syntax: number := l_ttod( <string-10>)
;;
;; Purpose: Converts an IEEE 10 byte into an IEEE 8 byte real.
;;
;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
ALIGN DWORD
PUBLIC l_ttod
PROC l_ttod far
push bp
mov bp, sp
xor ax, ax ; Push a 0 QUAD onto the stack.
push ax
push ax
push ax
push ax
mov bx, sp ; Save our QUAD address.
push ds ; Save what we mangle...
push si
push di
push bx
inc ax ; Get the address of our double.
push ax
call _hb_parc
pop bx
pop bx ; Retrieve Quad address.
mov ds, dx ; Return from _hb_parc is source.
mov si, ax
mov es, dx ; Test for 0.
mov di, ax
xor ax, ax
mov cx, 5
rep scasw
je @@skip
mov ax, [ si + 8 ] ; Set flags for under/over flow.
and ah, 7fh
sub ax, 16383d - 1023d
and ah, 0f8h
js @@skip ; Underflow - result is already 0'd.
push ss ; Stack is destination.
pop es
mov di, bx
jne @@ovrf ; Overflow. ES:DI setup for result.
;;
;; This next step is kinda kludgy. The mantissa of an 8-IEEE is shifted
;; 4 bits from the 10-IEEE. But the assumed 1.0 of an 8-IEEE isn't in
;; the 10-IEEE. That means that we end up with a 3-bit shift and an
;; explicit 1 bit added (except for 0).
;;
mov cl, 3
inc si ; Skip over excess - need to check for
; rounding in the future.
lodsw
mov dl, ah
shr ax, cl
stosb
REPT 5
lodsb
mov ah, al
mov al, dl
mov dl, ah
shr ax, cl
stosb
ENDM
shr dl, cl ; Hold on to low 4 bits of dl.
lodsw ; Get ahold of mantissa and sign.
mov dh, ah ; Save sign.
and ah, 7fh
sub ax, 16383d - 1023d ; Convert exponent and move into pos.
inc cl
shl ax, cl
and dx, 800fh ; Mask out non- sign/mantissa.
or ax, dx ; Or into exponent everyting else.
stosw
@@skip: pop di ; Restore mangled registers.
pop si
pop ds
call _hb_retnd ; Make our call and return.
mov sp, bp
pop bp
ret
@@ovrf: xor ax, ax ; ES:DI points to return value.
dec ax
REPT 4
stosw
ENDM
jmp @@skip
ENDP
ENDS _prog
END
And now the one changed for 32 bits
;IDEAL
P586
MODEL FLAT,STDCALL
EXTRN _hb_parc:FAR,_hb_parnd:FAR, _hb_retclen:FAR, _hb_retnd:FAR
SEGMENT _prog dword public use32 'CODE'
ASSUME cs:_prog,ds:nothing,es:nothing
;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
;;
;; Syntax: string-10 := l_dtot( <number>)
;;
;; Purpose: Converts an IEEE 8 byte into an IEEE 10 byte real.
;;
;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
PUBLIC _HB_FUN_L_DTOT
_HB_FUN_L_DTOT PROC FAR
push bp
mov bp, sp
xor ax, ax ; Push a 0 TREAL onto the stack.
push ax
push ax
push ax
push ax
push ax
inc ax ; Get the address of our double.
push ax
call _hb_parnd
pop bx
mov bx, sp ; Base address of TREAL.
mov cx, 10 ; Setup return logic for __retclen.
push cx
push ss
push bx
push ds ; Save what we mangle...
push si
push di
mov ds, dx ; Return from __parnd is source.
mov si, ax
push ds ; Test for 0.
pop es
mov di, si
xor ax, ax
mov cx, 4
rep scasw
je @@skip
push ss ; Stack is destination.
pop es
mov di, bx
;;
;; This next step is kinda kludgy. The mantissa of an 8-IEEE is shifted
;; 4 bits from the 10-IEEE. But the assumed 1.0 of an 8-IEEE isn't in
;; the 10-IEEE. That means that we end up with a 3-bit shift and an
;; explicit 1 bit added (except for 0).
;;
mov cl, 5
xor ax, ax ; LSB will always be 0. First 3 bits
stosb ; of next nibble will also be 0.
REPT 6
lodsb
rol ax, 1
rol ax, 1
rol ax, 1
stosb
shl ah, cl
ENDM
lodsb ; Special processing for last byte to
rol ax, 1 ; keep the start of the mantissa out
rol ax, 1 ; of it.
rol ax, 1
rol ax, 1
stc
rcr al, 1
stosb
;;
;; We have the LS-nibble of the exponent in AH now. Load the rest
;; (including the sign), change the bias from 1023 (QUAD) to 16383
;; (TREAL), and store it all...
;;
lodsb
mov bh, al ; Save sign bit.
dec cl
shl ah, cl
rol ax, cl
and ah, 07h
add ax, 16383d - 1023d
and bh, 80h ; Move in sign.
or ah, bh
stosw
@@skip: pop di ; Restore mangled registers.
pop si
pop ds
call _hb_retclen ; Make our call and return.
mov sp, bp
pop bp
ret
ENDP
;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
;;
;; Syntax: number := l_ttod( <string-10>)
;;
;; Purpose: Converts an IEEE 10 byte into an IEEE 8 byte real.
;;
;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;
ALIGN DWORD
PUBLIC _HB_FUN_L_TTOD
_HB_FUN_L_TTOD PROC far
push bp
mov bp, sp
xor ax, ax ; Push a 0 QUAD onto the stack.
push ax
push ax
push ax
push ax
mov bx, sp ; Save our QUAD address.
push ds ; Save what we mangle...
push si
push di
push bx
inc ax ; Get the address of our double.
push ax
call _hb_parc
pop bx
pop bx ; Retrieve Quad address.
mov ds, dx ; Return from __parc is source.
mov si, ax
mov es, dx ; Test for 0.
mov di, ax
xor ax, ax
mov cx, 5
rep scasw
je @@skip1
mov ax, [ si + 8 ] ; Set flags for under/over flow.
and ah, 7fh
sub ax, 16383d - 1023d
and ah, 0f8h
js @@skip1 ; Underflow - result is already 0'd.
push ss ; Stack is destination.
pop es
mov di, bx
jne @@ovrf ; Overflow. ES:DI setup for result.
;;
;; This next step is kinda kludgy. The mantissa of an 8-IEEE is shifted
;; 4 bits from the 10-IEEE. But the assumed 1.0 of an 8-IEEE isn't in
;; the 10-IEEE. That means that we end up with a 3-bit shift and an
;; explicit 1 bit added (except for 0).
;;
mov cl, 3
inc si ; Skip over excess - need to check for
; rounding in the future.
lodsw
mov dl, ah
shr ax, cl
stosb
REPT 5
lodsb
mov ah, al
mov al, dl
mov dl, ah
shr ax, cl
stosb
ENDM
shr dl, cl ; Hold on to low 4 bits of dl.
lodsw ; Get ahold of mantissa and sign.
mov dh, ah ; Save sign.
and ah, 7fh
sub ax, 16383d - 1023d ; Convert exponent and move into pos.
inc cl
shl ax, cl
and dx, 800fh ; Mask out non- sign/mantissa.
or ax, dx ; Or into exponent everyting else.
stosw
@@skip1: pop di ; Restore mangled registers.
pop si
pop ds
call _hb_retnd ; Make our call and return.
mov sp, bp
pop bp
ret
@@ovrf: xor ax, ax ; ES:DI points to return value.
dec ax
REPT 4
stosw
ENDM
jmp @@skip1
ENDP
ENDS _prog
END
Im using tasm32 compiling with /zi /ml
Regards
Luiz
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 9/10/2003
 
 

Re:help with asm

Hi Luiz,
Quote
I has an asm code but is gpfing
The function i used properly on 16bits code, but now i need the same
to work on 32 bits
1. Don't use FAR procedures in FLAT model.
2. Don't modify any "segment" registers there.
 

Re:help with asm

Vasya Pupkin wrote:
Quote
Hi Luiz,

>I has an asm code but is gpfing
>The function i used properly on 16bits code, but now i need the same
>to work on 32 bits

1. Don't use FAR procedures in FLAT model.
2. Don't modify any "segment" registers there.
2a. Don't do _anything_ to or with segment registers, _at_all_.
3. Don't use 16bit registers for addresses.
4. Don't push/pop 16bit registers.
5. Don't use 16bit registers for "rep" counters
 

{smallsort}

Re:help with asm

Hi Bob,
Quote
>1. Don't use FAR procedures in FLAT model.
>2. Don't modify any "segment" registers there.

2a. Don't do _anything_ to or with segment registers, _at_all_.
We can use them as prefixes (e.g. FS in SEH).
Quote
3. Don't use 16bit registers for addresses.
4. Don't push/pop 16bit registers.
5. Don't use 16bit registers for "rep" counters
Yes, and a lot of other "don'ts" ;-)
 

Re:help with asm

Vasya Pupkin wrote:
Quote
>2a. Don't do _anything_ to or with segment registers, _at_all_.

We can use them as prefixes (e.g. FS in SEH).
Yes, but that kind of thing is very rare. Better for the learner to
have "never use them" drummed in, then later wonder "If I never use
them, how do I.....and so learn the exception to the rule.)
Quote
Yes, and a lot of other "don'ts" ;-)
<VBG>
 

Re:help with asm

Hi Bob,
Quote
>We can use them as prefixes (e.g. FS in SEH).
Yes, but that kind of thing is very rare. Better for the learner to
have "never use them" drummed in, then later wonder "If I never use
them, how do I.....and so learn the exception to the rule.)
OK. I agree.
 

Re:help with asm

Hello Friends
Thanks for all reply
so can you point what lines i should change
Some of then is
ax to eax
bx to ebx
cx to ecx
dx to edx
di to edi
Regards
Luiz
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.525 / Virus Database: 322 - Release Date: 9/10/2003
 

Re:help with asm

Luiz Rafael Culik Guimaraes wrote:
Quote
so can you point what lines i should change
Almost every line needs to be changed.
Quote
Some of then is
ax to eax
Yes, but not blindly. You need to know what each line is doing, and
only change those that need to be changed, and leave the others alone.
See our previous replys for the list of things that you most need to
change.
If you picked up this code from somewhere, you might be better off
seeing if they have a 32bit version available.