This program reads the boot sector from disk A and displays it in hexadecimal and ASCII format 16 bytes at a time. It resets the disk system, reads the boot sector into a buffer, and then calls procedures to display the hexadecimal address, hexadecimal values of each byte, and ASCII equivalents of the bytes. Errors are displayed if the disk reset or reading the boot sector fails.
1. APPENDER.ASM
;Program APPENDER.ASM: Append a short message line to a
text file.
;
.MODEL SMALL
.DATA
FILENAME DB 'letter.txt',0
HANDLE DW ?
FBUFF DB 0DH,0AH,'This line was not here
before...',0DH,0AH
STAT DB 'The file LETTER.TXT has been
appended',0DH,0AH,'$'
FLEN EQU STAT - FBUFF ;calculate length of FBUFF
OEMSG DB 'Cannot open LETTER.TXT.$'
MEMSG DB 'Cannot position file pointer.$'
WFMSG DB 'Cannot write to LETTER.TXT.$'
CFMSG DB 'Cannot close LETTER.TXT.$'
.CODE
2. .STARTUP
CALL OPENFILE ;open LETTER.TXT
JC EXIT ;jump if error
CALL MOVEPTR ;move file pointer to end of file
CALL WRITEFILE ;write to LETTER.TXT
CALL CLOSEFILE ;close LETTER.TXT
EXIT: .EXIT
OPENFILE PROC NEAR
MOV AH,3DH ;open file with handle function
LEA DX,FILENAME ;set up pointer to ASCIIZ string
MOV AL,2 ;read/write access
INT 21H ;DOS call
JC OPENERR ;jump if error
MOV HANDLE,AX ;save file handle
RET
OPENERR: LEA DX,OEMSG ;set up pointer to error
message
3. MOV AH,9 ;display string function
INT 21H ;DOS call
STC ;set error flag
RET
OPENFILE ENDP
MOVEPTR PROC NEAR
MOV AH,42H ;position file pointer function
MOV AL,2 ;offset from end method
MOV BX,HANDLE ;load file handle
MOV CX,0 ;offset = 0 from end
MOV DX,0
INT 21H ;DOS call
JC MOVERR
RET
MOVERR: LEA DX,MEMSG ;set up pointer to error
message
MOV AH,9 ;display string function
INT 21H ;DOS call
4. STC ;set error flag
RET
MOVEPTR ENDP
WRITEFILE PROC NEAR
MOV AH,40H ;write to file function
MOV BX,HANDLE ;load file handle
LEA DX,FBUFF ;set up pointer to data buffer
MOV CL,FLEN ;load buffer length
SUB CH,CH ;fix bytes-to-write value
INT 21H ;DOS call
JC WRITERR ;jump if error
RET
WRITERR: LEA DX,WFMSG ;set up pointer to error
message
MOV AH,9 ;display string function
INT 21H ;DOS call
STC ;set error flag
5. EOFF: RET
WRITEFILE ENDP
CLOSEFILE PROC NEAR
MOV AH,3EH ;close file with handle function
MOV BX,HANDLE ;load file handle
INT 21H ;DOS call
JC CLOSERR ;jump if error
RET
CLOSERR: LEA DX,CFMSG ;set up pointer to error
message
MOV AH,9 ;display string function
INT 21H ;DOS call
STC ;set error flag
RET
CLOSEFILE ENDP
END
6. APPENDER.EXE
appender.lst
Microsoft (R) Macro Assembler Version 6.14.8444
03/25/06 09:54:54
appender.asm Page 1 - 1
;Program APPENDER.ASM: Append a
short message line to a text file.
;
.MODEL SMALL
0000 .DATA
0000 6C 65 74 74 65 72 FILENAME DB 'letter.txt',0
2E 74 78 74 00
000B 0000 HANDLE DW ?
000D 0D 0A 54 68 69 73 FBUFF DB 0DH,0AH,'This
line was not here before...',0DH,0AH
20 6C 69 6E 65 20
77 61 73 20 6E 6F
7. 74 20 68 65 72 65
20 62 65 66 6F 72
65 2E 2E 2E 0D 0A
0031 54 68 65 20 66 69 STAT DB 'The file
LETTER.TXT has been appended',0DH,0AH,'$'
6C 65 20 4C 45 54
54 45 52 2E 54 58
54 20 68 61 73 20
62 65 65 6E 20 61
70 70 65 6E 64 65
64 0D 0A 24
= 0024 FLEN EQU STAT - FBUFF
;calculate length of FBUFF
0059 43 61 6E 6E 6F 74 OEMSG DB 'Cannot open
LETTER.TXT.$'
20 6F 70 65 6E 20
4C 45 54 54 45 52
2E 54 58 54 2E 24
0071 43 61 6E 6E 6F 74 MEMSG DB 'Cannot
position file pointer.$'
8. 20 70 6F 73 69 74
69 6F 6E 20 66 69
6C 65 20 70 6F 69
6E 74 65 72 2E 24
008F 43 61 6E 6E 6F 74 WFMSG DB 'Cannot write
to LETTER.TXT.$'
20 77 72 69 74 65
20 74 6F 20 4C 45
54 54 45 52 2E 54
58 54 2E 24
00AB 43 61 6E 6E 6F 74 CFMSG DB 'Cannot close
LETTER.TXT.$'
20 63 6C 6F 73 65
20 4C 45 54 54 45
52 2E 54 58 54 2E
24
0000 .CODE
.STARTUP
9. 0017 E8 000F CALL OPENFILE ;open
LETTER.TXT
001A 72 09 JC EXIT ;jump if error
001C E8 0024 CALL MOVEPTR
;move file pointer to end of file
001F E8 003E CALL WRITEFILE
;write to LETTER.TXT
0022 E8 0058 CALL CLOSEFILE ;close
LETTER.TXT
0025 EXIT: .EXIT
0029 OPENFILE PROC NEAR
0029 B4 3D MOV AH,3DH ;open file
with handle function
002B 8D 16 0000 R LEA DX,FILENAME
;set up pointer to ASCIIZ string
002F B0 02 MOV AL,2 ;read/write
access
0031 CD 21 INT 21H ;DOS call
0033 72 04 JC OPENERR ;jump if
error
0035 A3 000B R MOV HANDLE,AX ;save
10. file handle
0038 C3 RET
0039 8D 16 0059 R OPENERR: LEA DX,OEMSG
;set up pointer to error message
003D B4 09 MOV AH,9 ;display
string function
003F CD 21 INT 21H ;DOS call
0041 F9 STC ;set error flag
0042 C3 RET
0043 OPENFILE ENDP
0043 MOVEPTR PROC NEAR
0043 B4 42 MOV AH,42H ;position
file pointer function
0045 B0 02 MOV AL,2 ;offset from
end method
0047 8B 1E 000B R MOV BX,HANDLE
;load file handle
004B B9 0000 MOV CX,0 ;offset
= 0 from end
004E BA 0000 MOV DX,0
11. 0051 CD 21 INT 21H ;DOS call
0053 72 01 JC MOVERR
0055 C3 RET
0056 8D 16 0071 R MOVERR: LEA DX,MEMSG
;set up pointer to error message
005A B4 09 MOV AH,9 ;display
string function
005C CD 21 INT 21H ;DOS call
005E F9 STC ;set error flag
005F C3 RET
0060 MOVEPTR ENDP
0060 WRITEFILE PROC NEAR
0060 B4 40 MOV AH,40H ;write to
file function
0062 8B 1E 000B R MOV BX,HANDLE
;load file handle
0066 8D 16 000D R LEA DX,FBUFF ;set
up pointer to data buffer
006A B1 24 MOV CL,FLEN ;load
buffer length
12. 006C 2A ED SUB CH,CH ;fix bytes-
to-write value
006E CD 21 INT 21H ;DOS call
0070 72 01 JC WRITERR ;jump if
error
0072 C3 RET
0073 8D 16 008F R WRITERR: LEA DX,WFMSG
;set up pointer to error message
0077 B4 09 MOV AH,9 ;display
string function
0079 CD 21 INT 21H ;DOS call
007B F9 STC ;set error flag
007C C3 EOFF: RET
007D WRITEFILE ENDP
007D CLOSEFILE PROC NEAR
007D B4 3E MOV AH,3EH ;close file
with handle function
007F 8B 1E 000B R MOV BX,HANDLE
;load file handle
0083 CD 21 INT 21H ;DOS call
13. 0085 72 01 JC CLOSERR ;jump if
error
0087 C3 RET
0088 8D 16 00AB R CLOSERR: LEA DX,CFMSG
;set up pointer to error message
008C B4 09 MOV AH,9 ;display
string function
008E CD 21 INT 21H ;DOS call
0090 F9 STC ;set error flag
0091 C3 RET
0092 CLOSEFILE ENDP
END
�Microsoft (R) Macro Assembler Version 6.14.8444
03/25/06 09:54:54
appender.asm Symbols 2 - 1
14. Segments and Groups:
N a m e Size Length Align Combine
Class
DGROUP . . . . . . . . . . . . . GROUP
_DATA . . . . . . . . . . . . . 16 Bit 00C4 Word
Public 'DATA'
_TEXT . . . . . . . . . . . . . 16 Bit 0092 Word Public
'CODE'
Procedures, parameters and locals:
N a m e Type Value Attr
CLOSEFILE . . . . . . . . . . . P Near 007D _TEXT
Length= 0015 Public
CLOSERR . . . . . . . . . . . L Near 0088 _TEXT
15. MOVEPTR . . . . . . . . . . . . P Near 0043 _TEXT
Length= 001D Public
MOVERR . . . . . . . . . . . . L Near 0056 _TEXT
OPENFILE . . . . . . . . . . . . P Near 0029 _TEXT
Length= 001A Public
OPENERR . . . . . . . . . . . L Near 0039 _TEXT
WRITEFILE . . . . . . . . . . . P Near 0060 _TEXT
Length= 001D Public
WRITERR . . . . . . . . . . . L Near 0073 _TEXT
EOFF . . . . . . . . . . . . . L Near 007C _TEXT
Symbols:
N a m e Type Value Attr
@CodeSize . . . . . . . . . . . Number 0000h
@DataSize . . . . . . . . . . . Number 0000h
@Interface . . . . . . . . . . . Number 0000h
@Model . . . . . . . . . . . . . Number 0002h
17. 0 Errors
BOOTSEC.ASM
;Program BOOTSEC.ASM: Display contents of disk A's boot
sector (with ASCII).
;
.MODEL SMALL
.DATA
BMSG DB 'Boot sector for diskette in drive
A:',0DH,0AH,0DH,0AH,'$'
EMSG1 DB 'Error! Can not reset diskette
system.',0DH,0AH,'$'
EMSG2 DB 'Error! Can not read boot sector.',0DH,0AH,'$'
BLANK DB ' $'
PRESS DB 0DH,0AH,'Press any key for next 256 bytes...'
CRLF DB 0DH,0AH,'$'
DBUF DB 512 DUP(0)
.CODE
.STARTUP
18. MOV AX,DS
MOV ES,AX ;set up extra segment
MOV AH,0 ;reset disk function
MOV DL,0 ;drive A
INT 13H ;BIOS call
JNC OK
LEA DX,EMSG1 ;set up pointer to error message
PRE: MOV AH,9 ;display string function
INT 21H ;DOS call
JMP EXIT
OK: CALL READ ;read boot sector, first try
JNC OBM
CALL READ ;read boot sector, second try
JNC OBM
CALL READ ;read boot sector, last try
JNC OBM
LEA DX,EMSG2 ;set up pointer to error message
JMP PRE ;go process error
19. OBM: LEA DX,BMSG ;set up pointer to boot message
MOV AH,9 ;display string function
INT 21H ;DOS call
SUB SI,SI ;clear index pointer
CALL SHOWDTA ;show first half of DTA
LEA DX,PRESS ;set up pointer to press message
MOV AH,9 ;display string function
INT 21H ;DOS call
MOV AH,1 ;read keyboard function
INT 21H ;DOS call
LEA DX,CRLF ;set up pointer to crlf string
MOV AH,9 ;display string function
INT 21H ;DOS call
CALL SHOWDTA ;show second half of DTA
EXIT: .EXIT
READ PROC NEAR
LEA BX,DBUF ;set up pointer to DTA
20. MOV AH,2 ;read disk sectors function
MOV AL,1 ;read one sector
MOV DL,0 ;from drive A
MOV DH,0 ;head 0
MOV CX,1 ;sector 1
INT 13H ;BIOS call
RET
READ ENDP
SHOWDTA PROC NEAR
MOV CX,16 ;load line counter
NLYN: PUSH CX ;save line counter
MOV AX,SI ;load pointer address
CALL DISPHEX2 ;output hex address
MOV DL,':' ;load colon
MOV AH,2 ;display character function
INT 21H ;DOS call
MOV CX,16 ;load byte counter
21. NBYT: LEA DX,BLANK ;set up pointer to blank string
MOV AH,9 ;display string function
INT 21H ;DOS call
MOV AL,ES:DBUF[SI] ;get next byte
CALL DISPHEX ;output it
INC SI ;advance pointer
LOOP NBYT ;repeat for next byte
CALL SHOWASC ;output ASCII equivalents
LEA DX,CRLF ;set up pointer to crlf string
MOV AH,9 ;display string function
INT 21H ;DOS call
POP CX ;get line counter back
LOOP NLYN ;and repeat until done
RET
SHOWDTA ENDP
SHOWASC PROC NEAR
LEA DX,BLANK ;set up pointer to blank string
22. MOV AH,9 ;display string function
INT 21H ;DOS call
LEA DX,BLANK ;set up pointer to blank string
MOV AH,9 ;display string function
INT 21H ;DOS call
SUB SI,16 ;adjust pointer
PUSH CX ;save current counter
MOV CX,16 ;load character counter
GCHR: MOV DL,ES:DBUF[SI] ;get next byte
INC SI ;advance pointer
AND DL,7FH ;convert to 7-bit ASCII
CMP DL,20H ;is it printable?
JC BLNK ;no, go output a blank
CMP AL,80H ;is it still printable?
JNC BLNK
AOUT: MOV AH,2 ;display character function
INT 21H ;DOS call
LOOP GCHR ;repeat until done
23. POP CX ;get counter back
RET
BLNK: MOV DL,20H ;load blank character
JMP AOUT
SHOWASC ENDP
DISPHEX PROC NEAR
PUSH AX ;save number
SHR AL,1 ;shift upper nybble down
SHR AL,1
SHR AL,1
SHR AL,1
CMP AL,10 ;is nybble value less than 10?
JC NHA1 ;yes, go convert and display
ADD AL,7 ;add alpha bias
NHA1: ADD AL,30H ;add ASCII bias
MOV DL,AL ;load character
24. MOV AH,2 ;display character function
INT 21H ;DOS call
POP AX ;get number back
AND AL,0FH ;work with lower nybble
CMP AL,10 ;is it less than 10?
JC NHA2 ;yes, go convert and display
ADD AL,7 ;add alpha bias
NHA2: ADD AL,30H ;add ASCII bias
MOV DL,AL ;load character
MOV AH,2 ;display character function
INT 21H ;DOS call
RET
DISPHEX ENDP
DISPHEX2 PROC NEAR
PUSH AX ;save number
XCHG AH,AL ;get upper byte
CALL DISPHEX ;output it
25. POP AX ;get number back
CALL DISPHEX ;output lower byte
RET
DISPHEX2 ENDP
END
BOOTSEC.EXE
bootsec.lst
Microsoft (R) Macro Assembler Version 6.14.8444
03/25/06 09:56:10
bootsec.asm Page 1 - 1
;Program BOOTSEC.ASM: Display
contents of disk A's boot sector (with ASCII).
;
.MODEL SMALL
26. 0000 .DATA
0000 42 6F 6F 74 20 73 BMSG DB 'Boot sector for
diskette in drive A:',0DH,0AH,0DH,0AH,'$'
65 63 74 6F 72 20
66 6F 72 20 64 69
73 6B 65 74 74 65
20 69 6E 20 64 72
69 76 65 20 41 3A
0D 0A 0D 0A 24
0029 45 72 72 6F 72 21 EMSG1 DB 'Error! Can not
reset diskette system.',0DH,0AH,'$'
20 43 61 6E 20 6E
6F 74 20 72 65 73
65 74 20 64 69 73
6B 65 74 74 65 20
73 79 73 74 65 6D
2E 0D 0A 24
0051 45 72 72 6F 72 21 EMSG2 DB 'Error! Can not
read boot sector.',0DH,0AH,'$'
20 43 61 6E 20 6E
27. 6F 74 20 72 65 61
64 20 62 6F 6F 74
20 73 65 63 74 6F
72 2E 0D 0A 24
0074 20 24 BLANK DB ' $'
0076 0D 0A 50 72 65 73 PRESS DB 0DH,0AH,'Press
any key for next 256 bytes...'
73 20 61 6E 79 20
6B 65 79 20 66 6F
72 20 6E 65 78 74
20 32 35 36 20 62
79 74 65 73 2E 2E
2E
009B 0D 0A 24 CRLF DB 0DH,0AH,'$'
009E 0200 [ DBUF DB 512 DUP(0)
00
]
28. 0000 .CODE
.STARTUP
0017 8C D8 MOV AX,DS
0019 8E C0 MOV ES,AX ;set up extra
segment
001B B4 00 MOV AH,0 ;reset disk
function
001D B2 00 MOV DL,0 ;drive A
001F CD 13 INT 13H ;BIOS call
0021 73 0A JNC OK
0023 8D 16 0029 R LEA DX,EMSG1 ;set up
pointer to error message
0027 B4 09 PRE: MOV AH,9 ;display
string function
0029 CD 21 INT 21H ;DOS call
002B EB 39 JMP EXIT
002D E8 003A OK: CALL READ ;read
boot sector, first try
0030 73 10 JNC OBM
0032 E8 0035 CALL READ ;read boot
sector, second try
29. 0035 73 0B JNC OBM
0037 E8 0030 CALL READ ;read boot
sector, last try
003A 73 06 JNC OBM
003C 8D 16 0051 R LEA DX,EMSG2 ;set up
pointer to error message
0040 EB E5 JMP PRE ;go process
error
0042 8D 16 0000 R OBM: LEA DX,BMSG ;set
up pointer to boot message
0046 B4 09 MOV AH,9 ;display string
function
0048 CD 21 INT 21H ;DOS call
004A 2B F6 SUB SI,SI ;clear index
pointer
004C E8 002D CALL SHOWDTA
;show first half of DTA
004F 8D 16 0076 R LEA DX,PRESS ;set up
pointer to press message
0053 B4 09 MOV AH,9 ;display string
function
0055 CD 21 INT 21H ;DOS call
0057 B4 01 MOV AH,1 ;read keyboard
30. function
0059 CD 21 INT 21H ;DOS call
005B 8D 16 009B R LEA DX,CRLF ;set up
pointer to crlf string
005F B4 09 MOV AH,9 ;display string
function
0061 CD 21 INT 21H ;DOS call
0063 E8 0016 CALL SHOWDTA ;show
second half of DTA
0066 EXIT: .EXIT
006A READ PROC NEAR
006A 8D 1E 009E R LEA BX,DBUF ;set up
pointer to DTA
006E B4 02 MOV AH,2 ;read disk
sectors function
0070 B0 01 MOV AL,1 ;read one
sector
0072 B2 00 MOV DL,0 ;from drive A
0074 B6 00 MOV DH,0 ;head 0
0076 B9 0001 MOV CX,1 ;sector 1
31. 0079 CD 13 INT 13H ;BIOS call
007B C3 RET
007C READ ENDP
007C SHOWDTA PROC NEAR
007C B9 0010 MOV CX,16 ;load line
counter
007F 51 NLYN: PUSH CX ;save line
counter
0080 8B C6 MOV AX,SI ;load pointer
address
0082 E8 0089 CALL DISPHEX2 ;output hex
address
0085 B2 3A MOV DL,':' ;load colon
0087 B4 02 MOV AH,2 ;display
character function
0089 CD 21 INT 21H ;DOS call
008B B9 0010 MOV CX,16 ;load
byte counter
008E 8D 16 0074 R NBYT: LEA DX,BLANK
;set up pointer to blank string
0092 B4 09 MOV AH,9 ;display string
32. function
0094 CD 21 INT 21H ;DOS call
0096 26: 8A 84 009E R MOV AL,ES:DBUF[SI]
;get next byte
009B E8 0047 CALL DISPHEX ;output
it
009E 46 INC SI ;advance pointer
009F E2 ED LOOP NBYT ;repeat for
next byte
00A1 E8 000C CALL SHOWASC
;output ASCII equivalents
00A4 8D 16 009B R LEA DX,CRLF ;set up
pointer to crlf string
00A8 B4 09 MOV AH,9 ;display string
function
00AA CD 21 INT 21H ;DOS call
00AC 59 POP CX ;get line counter back
00AD E2 D0 LOOP NLYN ;and repeat
until done
00AF C3 RET
00B0 SHOWDTA ENDP
33. 00B0 SHOWASC PROC NEAR
00B0 8D 16 0074 R LEA DX,BLANK ;set
up pointer to blank string
00B4 B4 09 MOV AH,9 ;display string
function
00B6 CD 21 INT 21H ;DOS call
00B8 8D 16 0074 R LEA DX,BLANK ;set
up pointer to blank string
00BC B4 09 MOV AH,9 ;display string
function
00BE CD 21 INT 21H ;DOS call
00C0 83 EE 10 SUB SI,16 ;adjust
pointer
00C3 51 PUSH CX ;save current
counter
00C4 B9 0010 MOV CX,16 ;load
character counter
00C7 26: 8A 94 009E R GCHR: MOV
DL,ES:DBUF[SI] ;get next byte
00CC 46 INC SI ;advance pointer
00CD 80 E2 7F AND DL,7FH ;convert
to 7-bit ASCII
34. 00D0 80 FA 20 CMP DL,20H ;is it
printable?
00D3 72 0C JC BLNK ;no, go output
a blank
00D5 3C 80 CMP AL,80H ;is it still
printable?
00D7 73 08 JNC BLNK
00D9 B4 02 AOUT: MOV AH,2 ;display
character function
00DB CD 21 INT 21H ;DOS call
00DD E2 E8 LOOP GCHR ;repeat until
done
00DF 59 POP CX ;get counter back
00E0 C3 RET
00E1 B2 20 BLNK: MOV DL,20H ;load
blank character
00E3 EB F4 JMP AOUT
00E5 SHOWASC ENDP
00E5 DISPHEX PROC NEAR
35. 00E5 50 PUSH AX ;save number
00E6 D0 E8 SHR AL,1 ;shift upper
nybble down
00E8 D0 E8 SHR AL,1
00EA D0 E8 SHR AL,1
00EC D0 E8 SHR AL,1
00EE 3C 0A CMP AL,10 ;is nybble
value less than 10?
00F0 72 02 JC NHA1 ;yes, go convert
and display
00F2 04 07 ADD AL,7 ;add alpha bias
00F4 04 30 NHA1: ADD AL,30H ;add
ASCII bias
00F6 8A D0 MOV DL,AL ;load
character
00F8 B4 02 MOV AH,2 ;display
character function
00FA CD 21 INT 21H ;DOS call
00FC 58 POP AX ;get number back
00FD 24 0F AND AL,0FH ;work with
lower nybble
00FF 3C 0A CMP AL,10 ;is it less than
36. 10?
0101 72 02 JC NHA2 ;yes, go convert
and display
0103 04 07 ADD AL,7 ;add alpha bias
0105 04 30 NHA2: ADD AL,30H ;add
ASCII bias
0107 8A D0 MOV DL,AL ;load
character
0109 B4 02 MOV AH,2 ;display
character function
010B CD 21 INT 21H ;DOS call
010D C3 RET
010E DISPHEX ENDP
010E DISPHEX2 PROC NEAR
010E 50 PUSH AX ;save number
010F 86 E0 XCHG AH,AL ;get upper
byte
0111 E8 FFD1 CALL DISPHEX ;output
it
0114 58 POP AX ;get number back
37. 0115 E8 FFCD CALL DISPHEX ;output
lower byte
0118 C3 RET
0119 DISPHEX2 ENDP
END
�Microsoft (R) Macro Assembler Version 6.14.8444
03/25/06 09:56:10
bootsec.asm Symbols 2 - 1
Segments and Groups:
N a m e Size Length Align Combine
Class
DGROUP . . . . . . . . . . . . . GROUP
38. _DATA . . . . . . . . . . . . . 16 Bit 029E Word
Public 'DATA'
_TEXT . . . . . . . . . . . . . 16 Bit 0119 Word Public
'CODE'
Procedures, parameters and locals:
N a m e Type Value Attr
DISPHEX2 . . . . . . . . . . . . P Near 010E _TEXT
Length= 000B Public
DISPHEX . . . . . . . . . . . . P Near 00E5 _TEXT
Length= 0029 Public
NHA1 . . . . . . . . . . . . . L Near 00F4 _TEXT
NHA2 . . . . . . . . . . . . . L Near 0105 _TEXT
READ . . . . . . . . . . . . . . P Near 006A _TEXT
Length= 0012 Public
SHOWASC . . . . . . . . . . . . P Near 00B0 _TEXT
Length= 0035 Public
GCHR . . . . . . . . . . . . . L Near 00C7 _TEXT
39. AOUT . . . . . . . . . . . . . L Near 00D9 _TEXT
BLNK . . . . . . . . . . . . . L Near 00E1 _TEXT
SHOWDTA . . . . . . . . . . . . P Near 007C _TEXT
Length= 0034 Public
NLYN . . . . . . . . . . . . . L Near 007F _TEXT
NBYT . . . . . . . . . . . . . L Near 008E _TEXT
Symbols:
N a m e Type Value Attr
@CodeSize . . . . . . . . . . . Number 0000h
@DataSize . . . . . . . . . . . Number 0000h
@Interface . . . . . . . . . . . Number 0000h
@Model . . . . . . . . . . . . . Number 0002h
@Startup . . . . . . . . . . . . L Near 0000 _TEXT
@code . . . . . . . . . . . . . Text _TEXT
41. BUFF.ASM
;Procedure KEYBUFF: Place keystrokes into buffer until CR is
entered.
;
.MODEL SMALL
PUBLIC KEYBUFF ;for linking
.CODE
KEYBUFF PROC FAR
MOV CL,0 ;clear character counter
NEXTKEY: MOV AH,1 ;read keyboard function
INT 21H ;DOS call
MOV [DI],AL ;save character in buffer
INC DI ;advance buffer pointer
INC CL ;increment character counter
CMP AL,0DH ;was last keystroke a CR?
JNZ NEXTKEY ;jump if not
42. RET
KEYBUFF ENDP
END
BUFF.EXE
buff.lst
Microsoft (R) Macro Assembler Version 6.14.8444
03/25/06 09:57:11
buff.asm Page 1 - 1
;Procedure KEYBUFF: Place keystrokes
into buffer until CR is entered.
;
.MODEL SMALL
PUBLIC KEYBUFF ;for linking
43. 0000 .CODE
0000 KEYBUFF PROC FAR
0000 B1 00 MOV CL,0 ;clear
character counter
0002 B4 01 NEXTKEY: MOV AH,1 ;read
keyboard function
0004 CD 21 INT 21H ;DOS call
0006 88 05 MOV [DI],AL ;save
character in buffer
0008 47 INC DI ;advance buffer
pointer
0009 FE C1 INC CL ;increment
character counter
000B 3C 0D CMP AL,0DH ;was last
keystroke a CR?
000D 75 F3 JNZ NEXTKEY ;jump if
not
000F CB RET
0010 KEYBUFF ENDP
END
44. �Microsoft (R) Macro Assembler Version 6.14.8444
03/25/06 09:57:11
buff.asm Symbols 2 - 1
Segments and Groups:
N a m e Size Length Align Combine
Class
DGROUP . . . . . . . . . . . . . GROUP
_DATA . . . . . . . . . . . . . 16 Bit 0000 Word
Public 'DATA'
_TEXT . . . . . . . . . . . . . 16 Bit 0010 Word Public
'CODE'
45. Procedures, parameters and locals:
N a m e Type Value Attr
KEYBUFF . . . . . . . . . . . . P Far 0000 _TEXT
Length= 0010 Public
NEXTKEY . . . . . . . . . . . L Near 0002 _TEXT
Symbols:
N a m e Type Value Attr
@CodeSize . . . . . . . . . . . Number 0000h
@DataSize . . . . . . . . . . . Number 0000h
@Interface . . . . . . . . . . . Number 0000h
@Model . . . . . . . . . . . . . Number 0002h
@code . . . . . . . . . . . . . Text _TEXT
@data . . . . . . . . . . . . . Text DGROUP
46. @fardata? . . . . . . . . . . . Text FAR_BSS
@fardata . . . . . . . . . . . . Text FAR_DATA
@stack . . . . . . . . . . . . . Text DGROUP
0 Warnings
0 Errors
The Intel Family of Microprocessors
James L. Antonakos
Lab #3: Assembling and Linking
Reference: Chapter 4
Introduction
The purpose of this experiment is to use the MASM assembler
and linker to convert your 80x86 assembly language source files
into executable code, such as .EXE and .COM files.
Procedure
1. This laboratory requires MASM 6.11 or later to be installed.
If you are using a different assembler and linker, you must
make whatever appropriate changes to the source files and
command syntax as necessary.
2. Enter and save the following source file, called TEST.ASM.
Save it in the root directory of drive C unless you have a
different working directory for your files.
47. 3. Open a DOS window and navigate to the directory where
TEST.ASM is stored. If you saved TEST.ASM in the root of
drive C, enter
C:
CD
to get to the root directory. If, for example, you saved
TEST.ASM in the directory C:MYFILES, then use
C:
CD MYFILES
to get into the MYFILES directory.
4. Enter the following command to assemble and link
TEST.ASM:
ML /Fl TEST.ASM
This will create TEST.LST (the list file), and TEST.EXE (the
executable code). Important: After the /F is a little l, not the
number 1. If you use a little f or a big L you will get an error.
5. Run the TEST.EXE program to verify it has been created.
Submit the .LST file with your lab writeup.
6. Choose three programs from the book (they are available on
the companion CD) and create EXE files from them. Execute the
programs and describe the results.
7. Write a one-page summary of what you learned during the
laboratory.
PAGE
1
48. test.asm
;Program TEST.ASM: Testing the MASM installation.
;
.MODEL SMALL
.DATA
MSG DB 'Way to go... MASM works!',13,10,'$'
.CODE
.STARTUP
LEA DX,MSG ;set up pointer to greeting
MOV AH,9 ;display string function
INT 21H ;DOS call
.EXIT
END