.model small
.code
TEST_WRITE_DECIMAL PROC
mov DX,12345
CALL WRITE_DECIMAL
int 20h ;Return to DOS
TEST_WRITE_DECIMAL ENDP
PUBLIC WRITE_DECIMAL
;-----------------------------------------------------------------------;
; This procedure writes a 16-bit, unsigned number in decimal notation. ;
; ;
; On Entry: DX N:16-bit, unsigned number. ;
; ;
; Uses: WRITE_HEX_DIGIT ;
;-----------------------------------------------------------------------;
WRITE_DECIMAL PROC NEAR
PUSH AX ;Save registers used here
PUSH CX
PUSH DX
PUSH SI
MOV AX,DX
MOV SI,10 ;Will divide by 10 using SI
XOR CX,CX ;Count of digits placed on stack
NON_ZERO:
XOR DX,DX ;Set upper word of N to 0
DIV SI ;Calculate n/10 and (N mod 10)
PUSH DX ;Push one digit onto the stack
INC CX ;One more digit added
OR AX,AX ;n =0 yet?
JNE NON_ZERO ;nope, continue
WRITE_DIGIT_LOOP:
POP DX ;Get the digits in reverse order
CALL WRITE_HEX_DIGIT
LOOP WRITE_DIGIT_LOOP
END_DECIMAL:
POP SI
POP DX
POP CX
POP AX
RET
WRITE_DECIMAL ENDP
PUBLIC WRITE_HEX
;-----------------------------------------------------------------------;
; This procedure converts the byte in the DL register to hex and writes ;
; the two hex digits at the current cursor position. ;
; ;
; On Entry; DL Byte to be converted to hex. ;
; Uses: WRITE_HEX_DIGIT ;
;-----------------------------------------------------------------------;
WRITE_HEX PROC ;Entry point
push cx ;Save registers used in this procedure
push dx
mov dh,dl ;Make a copy of byte
mov cx,4 ;Get the upper nibble in DL
shr dl,cl
call write_hex_digit ;Display first hex digit
mov dl,dh ;Get lower nibble into DL
and dl,0Fh ;Remove the upper nibble
call write_hex_digit ;Display second hex digit
pop dx
pop cx
ret
WRITE_HEX ENDP
PUBLIC WRITE_HEX_DIGIT
;-----------------------------------------------------------------------;
; This procedure converts the lower 4 bits of DL to a hex digit and ;
; writes it to the screen. ;
; ;
; On Entry; DL Lower 4 bits contain number to be printed ;
; in hex. ;
; ;
; Uses: WRITE_CHAR ;
;-----------------------------------------------------------------------;
WRITE_HEX_DIGIT PROC
PUSH DX ;Save registers used
CMP DL, 10 ;Is this nibble <10?
JAE HEX_LETTER ;No, convert to letter
ADD DL,"0" ;Yes, convert to a digit
JMP Short WRITE_DIGIT ;Now write this character
HEX_LETTER:
ADD DL,"A"-10 ;Convert to hex letter
WRITE_DIGIT:
CALL WRITE_CHAR ;Display the letter on the screen
POP DX ;Restore old value of DX
RET
WRITE_HEX_DIGIT ENDP
PUBLIC WRITE_CHAR
;-----------------------------------------------------------------------;
; This procedure prints a character on the screen using the DOS ;
; function call. ;
; ;
; On Entry: DL Byte to print on the screen. ;
;-----------------------------------------------------------------------;
WRITE_CHAR PROC
PUSH AX
MOV AH,2 ;Call for character output
INT 21h ;Output character in DL
POP AX ;Restore old value in AX
RET ;And return
WRITE_CHAR ENDP
END TEST_WRITE_DECIMAL
Masm and com files
Ok any assembly experts out there know why my following asm code is refusing to convert to a com file?
Ok I should mention this code if from peter norton's old assembly book I currently reading through and I haven't had any problems so far up to now I'm on chapter 10.
I'm using ml -omf video_io.asm with masm 8.0 to compile and then 16bit linker to link link video_io.asm and finally exe2bin video_io video_io.com to create a com file I can run.
The last program I was able to assemble and convert to com file and ran without a problem and I only added a new procedure and now it refuses to be converted to a com file but exe2bin isn't giving me any errors?
Only thing I can think of is my asm file is getting too big for a com file?
Yay! I actually know the awnser to a question in here! (can't belive anyone else doesn't though...)
You shouldn't be using exe2bin, I vaugely remember trying it at some point but it is quite difficult to do this conversion as far as I know. Exe files can contain segements, fixups and stuff where as com files can't, so depending on options you have used (like .DATA?) you might not be able to convert it.
There is a solutiuon to your problem thoug. You can use .model TINY and some command line option (can't remember which one, /t ?) to tell masm to compile/link directly to a com file. And depending on your version / platform that your compiling for you might have to set ORG 0x100 to originate your program at 0x0100 (DOS requires this for example)
You shouldn't be using exe2bin, I vaugely remember trying it at some point but it is quite difficult to do this conversion as far as I know. Exe files can contain segements, fixups and stuff where as com files can't, so depending on options you have used (like .DATA?) you might not be able to convert it.
There is a solutiuon to your problem thoug. You can use .model TINY and some command line option (can't remember which one, /t ?) to tell masm to compile/link directly to a com file. And depending on your version / platform that your compiling for you might have to set ORG 0x100 to originate your program at 0x0100 (DOS requires this for example)
Quote:Original post by Egelsoft
Yay! I actually know the awnser to a question in here! (can't belive anyone else doesn't though...)
You shouldn't be using exe2bin, I vaugely remember trying it at some point but it is quite difficult to do this conversion as far as I know. Exe files can contain segements, fixups and stuff where as com files can't, so depending on options you have used (like .DATA?) you might not be able to convert it.
There is a solutiuon to your problem thoug. You can use .model TINY and some command line option (can't remember which one, /t ?) to tell masm to compile/link directly to a com file. And depending on your version / platform that your compiling for you might have to set ORG 0x100 to originate your program at 0x0100 (DOS requires this for example)
Yeah I know about using tiny and org 100h before main procedure but it's been working fine so far without using either and I tried using both here and made no difference.
I haven't tried /t command line option so maybe that will make a difference?
I'll let you know but I think my problem has something to do with using NEAR keyword but I don't know what that's for since book didn't explain it yet.
Anyways I'll try to see if I can get masm to make a com exe without going through exe2bin since I haven't been able to get it do so without using exe2bin hence all the extra steps I'm taking to make my com exe.
I guess I'll have to make a batch file or figure out how to get it to use my 16bit linker instead of the 32bit one that comes with VS2005 since I know the 32bit linker can't make com files.
Ok we were both wrong since you won't believe what was causing the problem!
Apparently exe2bin cannot make com files if you use program name is longer than 8 letters!
That's why video_io converted to a com file without problems but as soon as I tried video_io2 it just kept spitting out a exe.
I changed video_io2 to videoio2 and now it makes a COM file fine.
Duh-
gotta remember that next time I'm working with DOS 8.3 limitation filename programs in the future!
Apparently exe2bin cannot make com files if you use program name is longer than 8 letters!
That's why video_io converted to a com file without problems but as soon as I tried video_io2 it just kept spitting out a exe.
I changed video_io2 to videoio2 and now it makes a COM file fine.
Duh-
gotta remember that next time I'm working with DOS 8.3 limitation filename programs in the future!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement