Code sample: 8086 assembler

Once upon a time, I had to write some low-level device handlers for a proprietary system. This is part of one of them, written for a once-popular assembler (hint: not the one from the Evil Empire).


.MODEL	large
.186

UP	EQU	1
DOWN	EQU	0

CONT_BASE		EQU	0FF00H
EOI_REGISTER		EQU	CONT_BASE + 022H
TIMER_CONTROL_REGISTER	EQU	CONT_BASE + 032H
TIMER_CTL		EQU	CONT_BASE + 00032H
TIMER0_CNT		EQU	CONT_BASE + 00050H
TIMER0_MAXA		EQU	CONT_BASE + 00050H
TIMER0_MAXB		EQU	CONT_BASE + 00054H
TIMER0_CTL		EQU	CONT_BASE + 00056H
TIMER1_CNT		EQU	CONT_BASE + 00058H
TIMER1_MAXA		EQU	CONT_BASE + 0005AH
TIMER1_MAXB		EQU	CONT_BASE + 0005CH
TIMER1_CTL		EQU	CONT_BASE + 0005EH
TIMER2_MAX		EQU	CONT_BASE + 00062H
TIMER2_CTL		EQU	CONT_BASE + 00066H

NON_SPECIFIC_EOI	EQU	08000H
YARD_INCREMENT		EQU	010000000000B
YARD_DECREMENT		EQU	01000000000000B

DGROUP	group	_DATA, _BSS

_DATA	segment	word	public	'DATA'
@curseg ENDS

_BSS	segment	word	public	'BSS'
@curseg ENDS

EXTRN	_dt_ymppr:WORD
EXTRN	_dt_ymdydx:WORD
EXTRN	_io_evnt:DWORD

EXTRN	AAEVSIG:far

assume	cs:_TEXT,ds:DGROUP

_TEXT	segment	byte	public	'CODE'

	public	_dt_ym0
	public	_dt_ym1

_dt_ym0	proc	far

	push	ax
	push	bx
	push	dx
	xor	ax,ax
	mov	dx,TIMER1_CNT
	in	al,dx
	or	al,al
	jnz	FIXCOUNT0
	xor	ax,ax
	out	dx,ax
	mov	dx,TIMER0_CNT
	out	dx,ax
	jmp	SIGDEC
FIXCOUNT0:
	mov	bx,ax
	mov	ax,_dt_ymppr
	sub	ax,bx
	mov	dx,TIMER0_CNT
	out	dx,ax
	xor	ax,ax
	mov	dx,TIMER1_CNT
	out	dx,ax
	jmp	VAMOS0
SIGDEC:
	mov	_dt_ymdydx,DOWN
	push	word ptr 0FFFFH
	push	word ptr YARD_DECREMENT
	push	word ptr _io_evnt
	call	far ptr AAEVSIG
	add	sp,6
VAMOS0:
	mov	dx,EOI_REGISTER
	mov	ax,NON_SPECIFIC_EOI
	out	dx,ax
	pop	dx
	pop	bx
	pop	ax
	ret

_dt_ym0	endp

_dt_ym1	proc	far

	push	ax
	push	bx
	push	dx
	xor	ax,ax
	mov	dx,TIMER0_CNT
	in	al,dx
	or	al,al
	jnz	FIXCOUNT1
	xor	ax,ax
	out	dx,ax
	mov	dx,TIMER1_CNT
	out	dx,ax
	jmp	SIGINC
FIXCOUNT1:
	mov	bx,ax
	mov	ax,_dt_ymppr
	sub	ax,bx
	mov	dx,TIMER1_CNT
	out	dx,ax
	xor	ax,ax
	mov	dx,TIMER0_CNT
	out	dx,ax
	jmp	VAMOS1
SIGINC:
	mov	_dt_ymdydx,UP
	push	word ptr 0FFFFH
	push	word ptr YARD_INCREMENT
	push	word ptr _io_evnt
	call	far ptr AAEVSIG
	add	sp,6
VAMOS1:
	mov	dx,EOI_REGISTER
	mov	ax,NON_SPECIFIC_EOI
	out	dx,ax
	pop	dx
	pop	bx
	pop	ax
	ret

_dt_ym0	endp

@curseg ENDS
end

Return to language index.


A publication of the School of Tyrannus

Copyright © 1998, The School of Tyrannus
All rights reserved