In part I you used debug to create possibly the smallest program you will ever write.
Debug can also be used as a lightweight disassembler to inspect the code.
What's inside dow.com?
At the Dos prompt type: debug dow.com
At the indicated prompt type in the bolded commands and press the Enter key.
| Prompt |
Commands |
Enter |
Comment |
| - |
u |
enter |
; Unassemble the program
; Debug will kindly convert the hex ; opcodes to mnemonics ; the comments it does not do... |
| |
| 1481:0100 B42A |
MOV AH,2A |
|
; Move (MOV=opcode B4) function code
; 2A (get date) to AH register |
| |
| 1481:0102 CD21 |
INT 21 |
|
; Invoke Interrupt 21H with this
; function code parameter ; Return registers : ; CX=Year(1980-2099) DH=Month ; DL=Day ; AL=Day of week 00h=Sun .. 06h=Sat. |
| |
| 1481:0104 B44C |
MOV AH,4C |
|
; Move function code 4c (terminate
; process) to AH register ; Other register needed at call ; (AL=exit code) is already set |
| |
| 1481:0106 CD21 |
INT 21 |
|
; Invoke Interrupt 21H with this
; function code parameter ; This ends the current process and ; returns to the command interpreter
; passing exit code from AL to ; indicate completion status. ; Return Registers : None ; it never returns
; Thats all folks!
|
| |
| 1481:0108 2020 |
AND [BX+SI],AH |
|
; Garbage lying around in memory
; from here on down |
| |
What happens when dow runs?
| Prompt |
Commands |
Enter |
Comment |
| - |
G 106 |
enter |
; 'go (run) the program from 0100 ; until it hits a breakpoint at 0106 ; which is also the last instruction ; in this case. |
| |
AX=4C03 BX=0000 CX=07CF DX=0415 SP=FFFE BP=0000 SI=0000 DI=0000
DS=1481 ES=1481 SS=1481 CS=1481 IP=0106 NV UP EI PL NZ NA PO NC
1481:0106 CD21 INT 21
|
| |
| - |
Q |
enter |
; to quit |
When dow exits.
Various registers get set:
Register CX=ccyy so 07cf(hex) is 1999 (decimal)
Register DX=mmdd so 04h = April, 15h = 16+5=21st of the month
The register we're really interested in is the AX register. What AL register?. Ah, Well the AX register comes apart into two halves the AH and AL registers.
So the contents of the AL register are the second two characters of AX and
Register AL = AX=??dw
dw is the day of the week code.
00=Sun so 03=Wed
When dow exits, the value in AL is returned by the operating system to whoever called dow.com.
For batch files AL is made available as ERRORLEVEL.
In dowtest.bat we test ERRORLEVEL after calling dow.com to see what the day of the week is.
Ok, you can now truly say that you are an assembler programmer. Twenty years from now,
when the crew is discussing whether the base app and the tools can be made to fit on
one 8 Terabyte disc, you will be able to say: 'arrr... in my day, i wrote programs in
single digits'!
Well actually, program, but who's counting.
|