in the name of zero

July 29, 2006

the com file and menu.asm

Filed under: life and school

we were given some programs to do in our cs 217 class for practice.

1) palindrome checker
2) vowel and consonant counter
3) case inverter (uppercase to lowercase and vice versa)
4) string reverser
5) and lastly, a menu program that uses arrow keys (menu.asm)

i’ve done all the first four in both 16bit real mode (dos) and 32bit protected mode (linux) as the only difference would be the binary format (com vs elf) and function calling (realmode interrupts and int21h in dos in contrast to int 0x80 in linux). the algorithm still remains the same but i enjoyed doing them nevertheless.

[ the com file ]
it’s simply a plain 16 bit binary with entry point at 0x0100, ss at 0x07a3 and sp at 0xfffe. i found those values by messing with a debug.exe output with the values outlined in this site , hello world.

i quote from the site:

A .COM program has all its segment registers set to the same value, called the PSP, Program Segment Prefix, which DEBUG or DOS establishes at the first free area of memory. The stack pointer SP is set to FFFF, and two bytes of zeros are pushed, so SP winds up at FFFE. Then, execution begins at 0100. A .COM program basically uses only 16-bit offsets, so the segment registers can be loaded with anything (so long as they are equal) and the program will still work properly. Actually, once a .COM program has been loaded and is running, it can do absolutely anything it wants. It can change segment registers, or load more code, or anything else like this. (In Windows, it may be limited, but not when running under DOS).

my debug.exe output. relevant values are in bold.

dos@localhost C:\CS217>debug c:\cs217\test.com
-r
AX=0000  BX=0000  CX=00AA  DX=0000  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=07A3  ES=07A3  SS=07A3  CS=07A3  IP=0100   NV UP DI PL NZ NA PO NC

i guess that’s all there is to it for the .com binary format. at this point, i scrapped a86 and used nasmi instead to make com files for our class. with the added benefit that i’m used to using nasm (intel syntax also) for everything related to assembly.

[ menu.asm ]
of the five assembly tasks that were given, i found number five to be the most interesting. (come to think of it, i’ve never did any assembly in linux that prints a colored string.)

make a program that prints a menu, then use the up/down arrow keys to scroll thru the menu choices. indicate that a particular menu is highlighted by changing it’s color. also provide a “quit” choice.

to grainne, you’ll find this list useful.

up	72	; up arrowkey
down	80	; down arrowkey
return	13	; enter key

Comments »

The URI to TrackBack this entry is: http://gnurbs.blogsome.com/2006/07/29/the-com-file-and-menuasm/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Get free blog up and running in minutes with Blogsome | Theme designs available here