Hardware Reference
In-Depth Information
#include "../syscalnr.h" ! 1
rout0: MOV AX,mes0
! 25
.SECT .TEXT
! 2
JMP 9f
! 26
jumpstrt:
! 3
rout1: MOV AX,mes1
! 27
PUSH strt
! 4
JMP 9f
! 28
MOV BP,SP
! 5
rout2: MOV AX,mes2
! 29
PUSH PRINTF
! 6
JMP 9f
! 30
SYS
! 7
rout3: MOV AX,mes3
! 31
PUSH GETCHAR ! 8
JMP 9f
! 32
1: SYS
! 9
rout4: MOV AX,mes4
! 33
CMP AX,5
! 10
JMP 9f
! 34
JL 8f
! 11
rout5: MOV AX,mes5
! 35
CMPB AL,'0'
! 12
JMP 9f
! 36
JL 1b
! 13
rout6: MOV AX,mes6
! 37
CMPB AL,'9'
! 14
JMP 9f
! 38
JLE 2f
! 15
rout7: MOV AX,mes7
! 39
MOVB AL,'9'+1
! 16
JMP 9f
! 40
2: MOV BX,AX
! 17
rout8: MOV AX,mes8
! 41
AND BX,0Xf
! 18
JMP 9f
! 42
SAL BX,1
! 19
erout: MOV AX,emes
! 43
CALL tbl(BX)
! 20
9:
PUSH AX
! 44
JMP 1b
! 21
PUSH PRINTF ! 45
8: PUSH 0
! 22
SYS
! 46
PUSH EXIT
! 23
ADD SP,4
! 47
SYS
! 24
RET
! 48
.SECT .DATA
! 49
tbl: .WORD rout0,rout1,rout2,rout3,rout4,rout5,rout6,rout7,rout8,rout8,erout
! 50
mes0: .ASCIZ "This is a zero.\n"
! 51
mes1: .ASCIZ "How about a one.\n"
! 52
mes2: .ASCIZ "You asked for a two.\n"
! 53
mes3: .ASCIZ "The digit was a three.\n"
! 54
mes4: .ASCIZ "You typed a four.\n"
! 55
mes5: .ASCIZ "You preferred a five.\n"
! 56
mes6: .ASCIZ "A six was encountered.\n"
! 57
mes7: .ASCIZ "This is number seven.\n"
! 58
mes8: .ASCIZ "This digit is not accepted as an octal.\n"
! 59
emes: .ASCIZ "This is not a digit. Try again.\n"
! 60
strt:
.ASCIZ "Type an octal digit with a return. Stop on end of file.\n"
! 61
Figure C-18. A program demonstrating a multiway branch using a dispatch table.
through rout8 , each load the addresses of their private messages in AX , and then
jump to the second line of erout to output the message and finish the subroutine.
In order to get accustomed to the dispatch tables, the program should be traced
with several different input characters. As an exercise, the program can be changed
 
Search WWH ::




Custom Search