SlideShare a Scribd company logo
1 of 49
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
.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
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
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
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
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
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.$'
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
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
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
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
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
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
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
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
@Startup . . . . . . . . . . . . L Near 0000 _TEXT
@code . . . . . . . . . . . . . Text _TEXT
@data . . . . . . . . . . . . . Text DGROUP
@fardata? . . . . . . . . . . . Text FAR_BSS
@fardata . . . . . . . . . . . . Text FAR_DATA
@stack . . . . . . . . . . . . . Text DGROUP
CFMSG . . . . . . . . . . . . . Byte 00AB _DATA
EXIT . . . . . . . . . . . . . . L Near 0025 _TEXT
FBUFF . . . . . . . . . . . . . Byte 000D _DATA
FILENAME . . . . . . . . . . . . Byte 0000 _DATA
FLEN . . . . . . . . . . . . . . Number 0024h
HANDLE . . . . . . . . . . . . . Word 000B _DATA
MEMSG . . . . . . . . . . . . . Byte 0071 _DATA
OEMSG . . . . . . . . . . . . . Byte 0059 _DATA
STAT . . . . . . . . . . . . . . Byte 0031 _DATA
WFMSG . . . . . . . . . . . . . Byte 008F _DATA
0 Warnings
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
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
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
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
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
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
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
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
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
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
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
]
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
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
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
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
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
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
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
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
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
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
_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
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
@data . . . . . . . . . . . . . Text DGROUP
@fardata? . . . . . . . . . . . Text FAR_BSS
@fardata . . . . . . . . . . . . Text FAR_DATA
@stack . . . . . . . . . . . . . Text DGROUP
BLANK . . . . . . . . . . . . . Byte 0074 _DATA
BMSG . . . . . . . . . . . . . .Byte 0000 _DATA
CRLF . . . . . . . . . . . . . . Byte 009B _DATA
DBUF . . . . . . . . . . . . . . Byte 009E _DATA
EMSG1 . . . . . . . . . . . . . Byte 0029 _DATA
EMSG2 . . . . . . . . . . . . . Byte 0051 _DATA
EXIT . . . . . . . . . . . . . . L Near 0066 _TEXT
OBM . . . . . . . . . . . . . . L Near 0042 _TEXT
OK . . . . . . . . . . . . . . . L Near 002D _TEXT
PRESS . . . . . . . . . . . . . Byte 0076 _DATA
PRE . . . . . . . . . . . . . . L Near 0027 _TEXT
0 Warnings
0 Errors
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
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
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
�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'
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
@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.
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
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
Append Boot Sector Contents

More Related Content

Similar to Append Boot Sector Contents

The true story_of_hello_world
The true story_of_hello_worldThe true story_of_hello_world
The true story_of_hello_worldfantasy zheng
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly LanguageAhmed M. Abed
 
Assembly Language Lecture 3
Assembly Language Lecture 3Assembly Language Lecture 3
Assembly Language Lecture 3Motaz Saad
 
micro_lecture-ch-456.pptx
micro_lecture-ch-456.pptxmicro_lecture-ch-456.pptx
micro_lecture-ch-456.pptxAmnaShujaa
 
8085_MicroelectronicAndMicroprocess.pdf
8085_MicroelectronicAndMicroprocess.pdf8085_MicroelectronicAndMicroprocess.pdf
8085_MicroelectronicAndMicroprocess.pdfFloraKara
 
Assembly language
Assembly languageAssembly language
Assembly languagebryle12
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCIS321
 
0.my book draft chap 1
0.my book draft chap 10.my book draft chap 1
0.my book draft chap 1manhduc1811
 
15CSL48 MP&MC manual
15CSL48 MP&MC manual15CSL48 MP&MC manual
15CSL48 MP&MC manualRLJIT
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1Motaz Saad
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationWei-Ren Chen
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxvamsiyadav39
 

Similar to Append Boot Sector Contents (20)

The true story_of_hello_world
The true story_of_hello_worldThe true story_of_hello_world
The true story_of_hello_world
 
Mcs 17 solved assignment 2015- 16
Mcs 17 solved assignment 2015- 16Mcs 17 solved assignment 2015- 16
Mcs 17 solved assignment 2015- 16
 
Assemblers
AssemblersAssemblers
Assemblers
 
Part III: Assembly Language
Part III: Assembly LanguagePart III: Assembly Language
Part III: Assembly Language
 
System programs in C language.
System programs in C language.System programs in C language.
System programs in C language.
 
Assembly Language Lecture 3
Assembly Language Lecture 3Assembly Language Lecture 3
Assembly Language Lecture 3
 
micro_lecture-ch-456.pptx
micro_lecture-ch-456.pptxmicro_lecture-ch-456.pptx
micro_lecture-ch-456.pptx
 
1.pdf
1.pdf1.pdf
1.pdf
 
8085_MicroelectronicAndMicroprocess.pdf
8085_MicroelectronicAndMicroprocess.pdf8085_MicroelectronicAndMicroprocess.pdf
8085_MicroelectronicAndMicroprocess.pdf
 
Lecture6
Lecture6Lecture6
Lecture6
 
Loader
LoaderLoader
Loader
 
Assembly language
Assembly languageAssembly language
Assembly language
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential files
 
Exp 03
Exp 03Exp 03
Exp 03
 
0.my book draft chap 1
0.my book draft chap 10.my book draft chap 1
0.my book draft chap 1
 
Assembler
AssemblerAssembler
Assembler
 
15CSL48 MP&MC manual
15CSL48 MP&MC manual15CSL48 MP&MC manual
15CSL48 MP&MC manual
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate Representation
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptx
 

More from rossskuddershamus

As a human resources manager, you need to advise top leadership (CEO.docx
As a human resources manager, you need to advise top leadership (CEO.docxAs a human resources manager, you need to advise top leadership (CEO.docx
As a human resources manager, you need to advise top leadership (CEO.docxrossskuddershamus
 
As a homeowner, you have become more concerned about the energy is.docx
As a homeowner, you have become more concerned about the energy is.docxAs a homeowner, you have become more concerned about the energy is.docx
As a homeowner, you have become more concerned about the energy is.docxrossskuddershamus
 
As a healthcare professional, you will be working closely with o.docx
As a healthcare professional, you will be working closely with o.docxAs a healthcare professional, you will be working closely with o.docx
As a healthcare professional, you will be working closely with o.docxrossskuddershamus
 
As a future teacher exposed to the rising trend of blogs and adv.docx
As a future teacher exposed to the rising trend of blogs and adv.docxAs a future teacher exposed to the rising trend of blogs and adv.docx
As a future teacher exposed to the rising trend of blogs and adv.docxrossskuddershamus
 
As a fresh research intern, you are a part of the hypothetical.docx
As a fresh research intern, you are a part of the hypothetical.docxAs a fresh research intern, you are a part of the hypothetical.docx
As a fresh research intern, you are a part of the hypothetical.docxrossskuddershamus
 
As a fresh research intern, you are a part of the hypothetical Nat.docx
As a fresh research intern, you are a part of the hypothetical Nat.docxAs a fresh research intern, you are a part of the hypothetical Nat.docx
As a fresh research intern, you are a part of the hypothetical Nat.docxrossskuddershamus
 
As a former emergency department Registered Nurse for over seven.docx
As a former emergency department Registered Nurse for over seven.docxAs a former emergency department Registered Nurse for over seven.docx
As a former emergency department Registered Nurse for over seven.docxrossskuddershamus
 
As a doctorally prepared nurse, you are writing a Continuous Qua.docx
As a doctorally prepared nurse, you are writing a Continuous Qua.docxAs a doctorally prepared nurse, you are writing a Continuous Qua.docx
As a doctorally prepared nurse, you are writing a Continuous Qua.docxrossskuddershamus
 
As a consumer of information, do you generally look for objectivity .docx
As a consumer of information, do you generally look for objectivity .docxAs a consumer of information, do you generally look for objectivity .docx
As a consumer of information, do you generally look for objectivity .docxrossskuddershamus
 
As a center of intellectual life and learning, Timbuktua. had ver.docx
As a center of intellectual life and learning, Timbuktua. had ver.docxAs a center of intellectual life and learning, Timbuktua. had ver.docx
As a center of intellectual life and learning, Timbuktua. had ver.docxrossskuddershamus
 
ary AssignmentCertified medical administrative assistants (CMAAs) .docx
ary AssignmentCertified medical administrative assistants (CMAAs) .docxary AssignmentCertified medical administrative assistants (CMAAs) .docx
ary AssignmentCertified medical administrative assistants (CMAAs) .docxrossskuddershamus
 
As (or after) you read The Declaration of Independence, identify.docx
As (or after) you read The Declaration of Independence, identify.docxAs (or after) you read The Declaration of Independence, identify.docx
As (or after) you read The Declaration of Independence, identify.docxrossskuddershamus
 
ARTWORK Markus Linnenbrink HOWTOSURVIVE, 2012, epoxy resin .docx
ARTWORK Markus Linnenbrink HOWTOSURVIVE, 2012, epoxy resin  .docxARTWORK Markus Linnenbrink HOWTOSURVIVE, 2012, epoxy resin  .docx
ARTWORK Markus Linnenbrink HOWTOSURVIVE, 2012, epoxy resin .docxrossskuddershamus
 
AS 4678—2002www.standards.com.au © Standards Australia .docx
AS 4678—2002www.standards.com.au © Standards Australia .docxAS 4678—2002www.standards.com.au © Standards Australia .docx
AS 4678—2002www.standards.com.au © Standards Australia .docxrossskuddershamus
 
arugumentative essay on article given belowIn Parents Keep Chil.docx
arugumentative essay on article given belowIn Parents Keep Chil.docxarugumentative essay on article given belowIn Parents Keep Chil.docx
arugumentative essay on article given belowIn Parents Keep Chil.docxrossskuddershamus
 
artsArticleCircling Round Vitruvius, Linear Perspectiv.docx
artsArticleCircling Round Vitruvius, Linear Perspectiv.docxartsArticleCircling Round Vitruvius, Linear Perspectiv.docx
artsArticleCircling Round Vitruvius, Linear Perspectiv.docxrossskuddershamus
 
ARTS & NATURE MARKETING PROJECT OF SHEFFIELDYang yux.docx
ARTS & NATURE MARKETING PROJECT OF SHEFFIELDYang yux.docxARTS & NATURE MARKETING PROJECT OF SHEFFIELDYang yux.docx
ARTS & NATURE MARKETING PROJECT OF SHEFFIELDYang yux.docxrossskuddershamus
 
ARTIGO ORIGINALRevista Cient.docx
ARTIGO ORIGINALRevista Cient.docxARTIGO ORIGINALRevista Cient.docx
ARTIGO ORIGINALRevista Cient.docxrossskuddershamus
 
Artist Analysis Project – Due Week 61)Powerpoint project at le.docx
Artist Analysis Project – Due Week 61)Powerpoint project at le.docxArtist Analysis Project – Due Week 61)Powerpoint project at le.docx
Artist Analysis Project – Due Week 61)Powerpoint project at le.docxrossskuddershamus
 
Artist Research Paper RequirementsYou are to write a 3 page double.docx
Artist Research Paper RequirementsYou are to write a 3 page double.docxArtist Research Paper RequirementsYou are to write a 3 page double.docx
Artist Research Paper RequirementsYou are to write a 3 page double.docxrossskuddershamus
 

More from rossskuddershamus (20)

As a human resources manager, you need to advise top leadership (CEO.docx
As a human resources manager, you need to advise top leadership (CEO.docxAs a human resources manager, you need to advise top leadership (CEO.docx
As a human resources manager, you need to advise top leadership (CEO.docx
 
As a homeowner, you have become more concerned about the energy is.docx
As a homeowner, you have become more concerned about the energy is.docxAs a homeowner, you have become more concerned about the energy is.docx
As a homeowner, you have become more concerned about the energy is.docx
 
As a healthcare professional, you will be working closely with o.docx
As a healthcare professional, you will be working closely with o.docxAs a healthcare professional, you will be working closely with o.docx
As a healthcare professional, you will be working closely with o.docx
 
As a future teacher exposed to the rising trend of blogs and adv.docx
As a future teacher exposed to the rising trend of blogs and adv.docxAs a future teacher exposed to the rising trend of blogs and adv.docx
As a future teacher exposed to the rising trend of blogs and adv.docx
 
As a fresh research intern, you are a part of the hypothetical.docx
As a fresh research intern, you are a part of the hypothetical.docxAs a fresh research intern, you are a part of the hypothetical.docx
As a fresh research intern, you are a part of the hypothetical.docx
 
As a fresh research intern, you are a part of the hypothetical Nat.docx
As a fresh research intern, you are a part of the hypothetical Nat.docxAs a fresh research intern, you are a part of the hypothetical Nat.docx
As a fresh research intern, you are a part of the hypothetical Nat.docx
 
As a former emergency department Registered Nurse for over seven.docx
As a former emergency department Registered Nurse for over seven.docxAs a former emergency department Registered Nurse for over seven.docx
As a former emergency department Registered Nurse for over seven.docx
 
As a doctorally prepared nurse, you are writing a Continuous Qua.docx
As a doctorally prepared nurse, you are writing a Continuous Qua.docxAs a doctorally prepared nurse, you are writing a Continuous Qua.docx
As a doctorally prepared nurse, you are writing a Continuous Qua.docx
 
As a consumer of information, do you generally look for objectivity .docx
As a consumer of information, do you generally look for objectivity .docxAs a consumer of information, do you generally look for objectivity .docx
As a consumer of information, do you generally look for objectivity .docx
 
As a center of intellectual life and learning, Timbuktua. had ver.docx
As a center of intellectual life and learning, Timbuktua. had ver.docxAs a center of intellectual life and learning, Timbuktua. had ver.docx
As a center of intellectual life and learning, Timbuktua. had ver.docx
 
ary AssignmentCertified medical administrative assistants (CMAAs) .docx
ary AssignmentCertified medical administrative assistants (CMAAs) .docxary AssignmentCertified medical administrative assistants (CMAAs) .docx
ary AssignmentCertified medical administrative assistants (CMAAs) .docx
 
As (or after) you read The Declaration of Independence, identify.docx
As (or after) you read The Declaration of Independence, identify.docxAs (or after) you read The Declaration of Independence, identify.docx
As (or after) you read The Declaration of Independence, identify.docx
 
ARTWORK Markus Linnenbrink HOWTOSURVIVE, 2012, epoxy resin .docx
ARTWORK Markus Linnenbrink HOWTOSURVIVE, 2012, epoxy resin  .docxARTWORK Markus Linnenbrink HOWTOSURVIVE, 2012, epoxy resin  .docx
ARTWORK Markus Linnenbrink HOWTOSURVIVE, 2012, epoxy resin .docx
 
AS 4678—2002www.standards.com.au © Standards Australia .docx
AS 4678—2002www.standards.com.au © Standards Australia .docxAS 4678—2002www.standards.com.au © Standards Australia .docx
AS 4678—2002www.standards.com.au © Standards Australia .docx
 
arugumentative essay on article given belowIn Parents Keep Chil.docx
arugumentative essay on article given belowIn Parents Keep Chil.docxarugumentative essay on article given belowIn Parents Keep Chil.docx
arugumentative essay on article given belowIn Parents Keep Chil.docx
 
artsArticleCircling Round Vitruvius, Linear Perspectiv.docx
artsArticleCircling Round Vitruvius, Linear Perspectiv.docxartsArticleCircling Round Vitruvius, Linear Perspectiv.docx
artsArticleCircling Round Vitruvius, Linear Perspectiv.docx
 
ARTS & NATURE MARKETING PROJECT OF SHEFFIELDYang yux.docx
ARTS & NATURE MARKETING PROJECT OF SHEFFIELDYang yux.docxARTS & NATURE MARKETING PROJECT OF SHEFFIELDYang yux.docx
ARTS & NATURE MARKETING PROJECT OF SHEFFIELDYang yux.docx
 
ARTIGO ORIGINALRevista Cient.docx
ARTIGO ORIGINALRevista Cient.docxARTIGO ORIGINALRevista Cient.docx
ARTIGO ORIGINALRevista Cient.docx
 
Artist Analysis Project – Due Week 61)Powerpoint project at le.docx
Artist Analysis Project – Due Week 61)Powerpoint project at le.docxArtist Analysis Project – Due Week 61)Powerpoint project at le.docx
Artist Analysis Project – Due Week 61)Powerpoint project at le.docx
 
Artist Research Paper RequirementsYou are to write a 3 page double.docx
Artist Research Paper RequirementsYou are to write a 3 page double.docxArtist Research Paper RequirementsYou are to write a 3 page double.docx
Artist Research Paper RequirementsYou are to write a 3 page double.docx
 

Recently uploaded

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

Append Boot Sector Contents

  • 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
  • 16. @Startup . . . . . . . . . . . . L Near 0000 _TEXT @code . . . . . . . . . . . . . Text _TEXT @data . . . . . . . . . . . . . Text DGROUP @fardata? . . . . . . . . . . . Text FAR_BSS @fardata . . . . . . . . . . . . Text FAR_DATA @stack . . . . . . . . . . . . . Text DGROUP CFMSG . . . . . . . . . . . . . Byte 00AB _DATA EXIT . . . . . . . . . . . . . . L Near 0025 _TEXT FBUFF . . . . . . . . . . . . . Byte 000D _DATA FILENAME . . . . . . . . . . . . Byte 0000 _DATA FLEN . . . . . . . . . . . . . . Number 0024h HANDLE . . . . . . . . . . . . . Word 000B _DATA MEMSG . . . . . . . . . . . . . Byte 0071 _DATA OEMSG . . . . . . . . . . . . . Byte 0059 _DATA STAT . . . . . . . . . . . . . . Byte 0031 _DATA WFMSG . . . . . . . . . . . . . Byte 008F _DATA 0 Warnings
  • 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
  • 40. @data . . . . . . . . . . . . . Text DGROUP @fardata? . . . . . . . . . . . Text FAR_BSS @fardata . . . . . . . . . . . . Text FAR_DATA @stack . . . . . . . . . . . . . Text DGROUP BLANK . . . . . . . . . . . . . Byte 0074 _DATA BMSG . . . . . . . . . . . . . .Byte 0000 _DATA CRLF . . . . . . . . . . . . . . Byte 009B _DATA DBUF . . . . . . . . . . . . . . Byte 009E _DATA EMSG1 . . . . . . . . . . . . . Byte 0029 _DATA EMSG2 . . . . . . . . . . . . . Byte 0051 _DATA EXIT . . . . . . . . . . . . . . L Near 0066 _TEXT OBM . . . . . . . . . . . . . . L Near 0042 _TEXT OK . . . . . . . . . . . . . . . L Near 002D _TEXT PRESS . . . . . . . . . . . . . Byte 0076 _DATA PRE . . . . . . . . . . . . . . L Near 0027 _TEXT 0 Warnings 0 Errors
  • 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