Reputation: 890
I made a program in assembler 8086 for my class and everything is working just fine. But beside making working program we have to make it use as low memory as possible. Could you give me some tips in that aspect? What should I write and what should I avoid?
The program is supposed to first print letter A on the screen and then in avery new line two more of letters of next letter in the alphabet, stop at Z and after pressing any key end program. For stopping until key is pressed i'm using: mov ah,00h int 16h Is it good way to do it?
Upvotes: 0
Views: 1320
Reputation: 356
Use these instructions:
INC (Register*) instead of ADD (Register*), 1
DEC (Register*) instead of SUB (Register*), 1
XOR (Register)(same register) instead of MOV (Register), 0 (Doesn't work with variables)
SHR (Register*), 1 instead of DIV (Register*), 2
SHR (Register*), 2 instead of DIV (Register*), 4
..
SHL (Register*), 1 instead of MUL (Register*), 2
..
*Register or variable
These optimizations makes the program faster AND the size larger
Upvotes: 0
Reputation: 11018
Most of what you want can be done in zero memory (counting only data, not the code itself). In general:
But to interact with the OS, you need to make BIOS calls and/or OS system calls; these require some memory (typically a small amount of stack space). In your case, you have to:
However, if you are serious about doing this in minimal memory, then there are a few hacks you can use.
On a PC, in traditional text mode, you can write characters straight to video RAM (address B800:0000 and further). This requires zero memory.
The cheapest way is to wait for a change of the BIOS keyboard buffer head (a change of the 16-bit content at address 041A hex). This requires zero memory. See also: http://support.microsoft.com/kb/60140
Try a simple ret
; it is not recommended but it might just work in some versions of MS-DOS. An even uglier escape is to jump to F000:FFF0
, which will reboot the machine. That's guaranteed to work in zero memory.
Upvotes: 1