flat assembler
Message board for the users of flat assembler.

Index > DOS > 32-bit to 16-bit conversion

Author
Thread Post new topic Reply to topic
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 09 Sep 2004, 11:39
I'm trying to convert a 32-bit program into a 16-bit one. I've finished most of it, but one routine is quite bothersome. This is it:

Code:
mov eax,[esp]
mov eax,[eax]
add dword [esp],4
    


How can I do this in 16-bit code? I can't seem to access [sp] directly, and doing something like:

Code:
mov di, sp
mov ax, [di]
add word [di], 2
    


doesn't work Sad

Any ideas? I can post the entire program if needed.

_________________
Charles Childers, Programmer
Post 09 Sep 2004, 11:39
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 09 Sep 2004, 12:55
Hy,
say, are you sure you want to do that?
sp is a pointer to a word to the stack

so if you do this

Code:
push word $1A $2B $3C
    


then stack will look like this:
Code:
 stack   sp+4  $1A   
         sp+2  $2B
         sp    $3C 
    

MATRIX
Post 09 Sep 2004, 12:55
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]
crc 09 Sep 2004, 13:17
Quote:
say, are you sure you want to do that?
sp is a pointer to a word to the stack


Yes I want to do this. This is a routine that handles inline integers in my compiler. It's a handler for it.

In a compiled function, I have:

... code ...
call dolit
dw value
... more code ...

This routine needs to get the value after the call, put the value in ax, and tell the machine to skip over the value. The only register it can't touch is SI. The 32-bit code *works perfectly*, but I can't figure out how to do it in 16-bit code.
Post 09 Sep 2004, 13:17
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 09 Sep 2004, 13:37
crc wrote:
Quote:
say, are you sure you want to do that?
sp is a pointer to a word to the stack


Yes I want to do this. This is a routine that handles inline integers in my compiler. It's a handler for it.

In a compiled function, I have:

... code ...
call dolit
dw value
... more code ...

This routine needs to get the value after the call, put the value in ax, and tell the machine to skip over the value. The only register it can't touch is SI. The 32-bit code *works perfectly*, but I can't figure out how to do it in 16-bit code.


oh its easy,
if you call, then the caller 's address is pushed onto stack
Code:
mov bx,sp <= here 's your address
now increase bx to get to data 
you can use it like
mov dx,bx <= for example if you want to pass it to write it to screen
    


MATRIX


Last edited by Matrix on 09 Sep 2004, 13:41; edited 1 time in total
Post 09 Sep 2004, 13:37
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]
crc 09 Sep 2004, 13:40
Thanks for the help MATRIX, I just got it to work Smile

Code:
        pop di                  ; SP>
        mov ax, [di]            ; Value @ [SP]
        add di, 2               ; skip DW VALUE
        push di                 ; >SP
    


* crc makes a note to mention your help in the documentation
Post 09 Sep 2004, 13:40
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 09 Sep 2004, 13:43
crc wrote:
Thanks for the help MATRIX, I just got it to work Smile

Code:
        pop di                  ; SP>
        mov ax, [di]            ; Value @ [SP]
        add di, 2               ; skip DW VALUE
        push di                 ; >SP
    


* crc makes a note to mention your help in the documentation


you're welcome Smile

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



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 09 Sep 2004, 14:34
Say,
i think with this message board we're like a team,
and we're way better than microsoft type teams
with this simple little message board,
imagine if 900 people helps each other making a program Smile

that whould be really cool Cool

someone writes a function => 2 people see the problem immediately, others take a look 10 people optimizes it in 10 minutes
here you are, a fully optimized function working smooth Smile

what a risc architecture

MATRIX
Post 09 Sep 2004, 14:34
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]
crc 09 Sep 2004, 14:48
Quote:
here you are, a fully optimized function working smooth


What if you don't want an optomized function?
Post 09 Sep 2004, 14:48
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 09 Sep 2004, 14:53
crc wrote:
Quote:
here you are, a fully optimized function working smooth


What if you don't want an optomized function?


then you just don't optimize it Smile

but you shouldn't write things like windows i think, its very large and under optimized, of course sometimes you may want to size optimize somtimes for example in a boot loader,
the team can work altogether on a project - that was my point of view
functions can be seperately programmed by many people, thus you will only need to copy the functions and paste Smile

MATRIX
Post 09 Sep 2004, 14:53
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]
crc 09 Sep 2004, 15:23
Quote:
but you shouldn't write things like windows i think, its very large and under optimized, of course sometimes you may want to size optimize somtimes for example in a boot loader, the team can work altogether on a project - that was my point of view functions can be seperately programmed by many people, thus you will only need to copy the functions and paste


I agree about Windows, and I understand your point.

The problem with copying/pasting functions is that they don't always mesh cleanly in an application. For example, I code most of my apps around a subset of RetroForth. This subset is written in assembly, but it doesn't cleanly interface with standard libraries, procedures, and so on. So I can share a source routine, but it won't be easy for you to use it unless your app has a similar internal design to mine. And that, I think, it the main problem with having large, loose-knit teams work on functions.

(Consider that if I had given the entire routine, rather than just the problem part, I'd have also had to give and explain the register uses, macros, etc.)
Post 09 Sep 2004, 15:23
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 09 Sep 2004, 15:33
May be MATRIX is thinking your entering a compo, maybe a 512b compo Wink . ?

\\\\||////
(@@)
ASHLEY4.
Post 09 Sep 2004, 15:33
View user's profile Send private message Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 09 Sep 2004, 15:42
Quote:
May be MATRIX is thinking your entering a compo, maybe a 512b compo?


The way things are currently looking, my entry will barely fit in 512 bytes once it's done Smile
Post 09 Sep 2004, 15:42
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 09 Sep 2004, 16:08
Ok,
i understand all of your point of views,
i can only say that we're creative,
you probably won't just cut and paste a code of other's
but there it might be no need to do this
there are or maybe differences between out programming techniques,
variable declaration modes, creating structures of program,
it primarily depends on the purpose of the program you ' re writing,
you might need to optimize for speed, code size, easy reading of code or nothing
in som cases:
ideas from a 3 line code snipplet could be very helpful too,
you can never know when you'll need that idea that is somewhere
out there - that you might never been thinking of.

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



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 09 Sep 2004, 16:24
My entry (a pmode cdplayer) was 200 bytes over, it tuck me about 2 hour's to get 100 bytes off, i thought this is going to be easy, but to get the other 100 bytes off tuck over a week. and still i had no space to turn the floppy motor off.

Any way just incase this is a good artical: http://www.assembly-journal.com/viewarticle.php?id=30&layout=html

\\\\\||////
(@@)
ASHLEY4.
Post 09 Sep 2004, 16:24
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 09 Sep 2004, 16:39
ASHLEY4 wrote:
My entry (a pmode cdplayer) was 200 bytes over, it tuck me about 2 hour's to get 100 bytes off, i thought this is going to be easy, but to get the other 100 bytes off tuck over a week. and still i had no space to turn the floppy motor off.

Any way just incase this is a good artical: http://www.assembly-journal.com/viewarticle.php?id=30&layout=html

\\\\\||////
(@@)
ASHLEY4.


Why whould you make such a thing?

you can find cd rom drives with play buttons Smile
you won't even need a computer for it, just give the drive +12v +5v gnd
and you're on

for example i use mp3 and m4a

MATRIX
Post 09 Sep 2004, 16:39
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]
crc 09 Sep 2004, 17:40
Quote:
you can find cd rom drives with play buttons
you won't even need a computer for it, just give the drive +12v +5v gnd
and you're on


What about sound? Do these CD-ROM drives have audio cards & jacks built in?

Heh, my entry is ~30 bytes over (and I had to leave out a lot of good stuff), but I'll have it done soon. It's nothing fancy at this point (an RPN calculator), but it has a 16-bit, subroutine-threaded Forth interpreter under the hood. With ~2k I could do a full Forth, but that's outside the point of this compo Smile
Post 09 Sep 2004, 17:40
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 09 Sep 2004, 17:51
crc wrote:
Quote:
you can find cd rom drives with play buttons
you won't even need a computer for it, just give the drive +12v +5v gnd
and you're on


What about sound? Do these CD-ROM drives have audio cards & jacks built in?

Heh, my entry is ~30 bytes over (and I had to leave out a lot of good stuff), but I'll have it done soon. It's nothing fancy at this point (an RPN calculator), but it has a 16-bit, subroutine-threaded Forth interpreter under the hood. With ~2k I could do a full Forth, but that's outside the point of this compo Smile


yes, they use 1 bit oversampling, and they have stereo analog outputs, and they also have digital outputs, for example i have one of them,
it can not only play, it can fast forward, and change to next, and stop additional to eject Smile
an simple 8x cdrom drive !

MATRIX
Post 09 Sep 2004, 17:51
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 09 Sep 2004, 20:45
Yes MATRIX you are right, mine has the button's on the front to play, next track etc too, but the point is not to have a cdplayer.
The point is to demo that You can setup vesa (including full vesa info), set A20, GDT, go to pmode, draw full 640x480 24bit image of a iPod, make a basic atapi driver, + menu that takes keyboard input, + prints to screen "Play","Stop",etc
All in 510bytes.
Remember we are in pmode, no fonts the letter "P" is 8 bytes *8 bytes * 4 (256),thats for one letter, 2 letters and thats it.
We have tricks to make it smaller, but you can see what we are up against.

crc, most cd/dvd drives have jack plugs (so head phone's are needed), but some very modern pc do not . The Forth interpreter sounds interesting.

\\\\||////
(@@)
ASHLEY4.
Post 09 Sep 2004, 20:45
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 18 Sep 2004, 21:36
Hy crc, i have some stack procedure for you Smile

Code:
org $100
push $b800
pop ss
mov sp,80*25*2
mov cx,200
times 12 push $0f68
pop dword [ss:1000]
pop dword [ss:1010]
pop dword [ss:1020]
int 20h
    


so according to this analogy heres a putpixel:

Code:
org $100
mov ax,$13
int 10h

push es

push word 100
mov bx,320*100+160
call poppixel

pop es

xor ax,ax
int 16h

mov ax,3
int 10h
int 20h

poppixel: ; procedure poppixel Very Happy
push $a000
pop es
pop ax
pop word [es:bx]
push ax
ret
    


crazy ha?

ps.: now you can see what's in the stack Smile
MATRIX
Post 18 Sep 2004, 21:36
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:  


< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.