Skip to content

Instantly share code, notes, and snippets.

@Karl-Han
Created April 15, 2019 14:18
Show Gist options
  • Save Karl-Han/0bb055a8ba09313415795f1240b5ae57 to your computer and use it in GitHub Desktop.
Save Karl-Han/0bb055a8ba09313415795f1240b5ae57 to your computer and use it in GitHub Desktop.
; Use opcode offset to jump to destination
data segment
num db 78h
addrs dw offset func0, offset func1, offset func2, offset func3
dw offset func4, offset func5, offset func6, offset func7
data ends
stack1 segment para stack
dw 10h dup(0)
stack1 ends
codeseg segment
start:
assume cs:codeseg, ds:data, ss:stack1
mov ax, data
mov ds, ax
xor di, di
mov bl, num
test bl, 0ffh
jz disp
next_bit:
; Deal with one bit
shr bl, 1
jc redirect
inc di
jmp next_bit
redirect:
shl di, 1
jmp addrs[di]
; Address table
func0:
mov dl, '0'
jmp disp
func1:
mov dl, '1'
jmp disp
func2:
mov dl, '2'
jmp disp
func3:
mov dl, '3'
jmp disp
func4:
mov dl, '4'
jmp disp
func5:
mov dl, '5'
jmp disp
func6:
mov dl, '6'
jmp disp
func7:
mov dl, '7'
jmp disp
func8:
mov dl, '8'
jmp disp
func9:
mov dl, '9'
jmp disp
disp:
mov ah, 02h
int 21h
mov ah, 4ch
int 21h
codeseg ends
end start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment