Skip to content

Commit

Permalink
Add Lab13(1,2)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhyy committed May 26, 2021
1 parent f9ce701 commit 5105165
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 0 deletions.
114 changes: 114 additions & 0 deletions Lab13/lab13_1.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
; Lab 13.1 - Interrupt Handler
; func: Display a string of text ends with 0
; args: (dh) = line(0~24), (dl) = column(0~79)
; (cl) = color, ds:si = where the string begins

; ## NOTES
;
; * `int 7ch` context
;
; AX=0B28 BX=0000 CX=0002 DX=0A0A SP=0000 BP=0000 SI=0000 DI=023F
; DS=0B28 ES=0000 SS=0B28 CS=0B2A IP=0036 NV UP EI PL NZ NA PO NC
; 0B2A:0036 CD7C INT 7C
; -t
;
; AX=0B28 BX=0000 CX=0002 DX=0A0A SP=FFFA BP=0000 SI=0000 DI=023F
; DS=0B28 ES=0000 SS=0B28 CS=0000 IP=0200 NV UP DI PL NZ NA PO NC
; 0000:0200 56 PUSH SI
;
;
;
; * `iret` context
; AX=0B28 BX=0000 CX=0002 DX=0A0A SP=FFFA BP=0000 SI=0000 DI=023F
; DS=0B28 ES=B800 SS=0B28 CS=0000 IP=0239 NV UP DI PL NZ NA PE NC
; 0000:0239 CF IRET
; -t
;
; AX=0B28 BX=0000 CX=0002 DX=0A0A SP=0000 BP=0000 SI=0000 DI=023F
; DS=0B28 ES=B800 SS=0B28 CS=0B2A IP=0038 NV UP EI PL NZ NA PO NC
; 0B2A:0038 B8004C MOV AX,4C00
;

assume cs:code
data segment
db "welcome to masm! ",0
data ends
code segment
start: ; Set Up the Interrupt Handler
mov ax,cs
mov ds,ax
mov si,offset do0
mov ax,0
mov es,ax
mov di,200h
mov cx,offset do0end-offset do0
cld
rep movsb
; Set Interrupt Vector Table
mov ax,0
mov es,ax
mov word ptr es:[7ch*4],200h ; offset
mov word ptr es:[7ch*4+2],0 ; segment
; Test the Handler
mov dh,10
mov dl,10
mov cl,2
mov ax,data
mov ds,ax
mov si,0
int 7ch
mov ax,4c00h
int 21h
; Interrupt Handler Start
do0: push si
push di
push bx
push bp
push ax
push dx
push cx
mov ax,0B800H
mov es,ax
mov al,0A0H
mov bl,dh
mul bl
mov bp,ax ; first column of the line
mov al,2
mul dl
add bp,ax ; exact position
mov di,0
mov dl,cl
mov ch,0
s: mov cl,ds:[si]
jcxz done
mov es:[bp+di],cl
mov es:[bp+di+1],dl
add di,2
inc si
jmp short s
done: pop cx
pop dx
pop ax
pop bp
pop bx
pop di
pop si
iret

do0end: nop

code ends
end start
91 changes: 91 additions & 0 deletions Lab13/lab13_2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
; Lab 13.2 - Interrupt Handler
; func: Loop
; args: (cx) = cycles; (bx) = offset

; ## NOTES
;
; * `int 7ch` context
;
; AX=B800 BX=FFF7 CX=0050 DX=0000 SP=0000 BP=0000 SI=0052 DI=0782
; DS=0B28 ES=B800 SS=0B28 CS=0B28 IP=003D NV UP EI PL NZ NA PE NC
; 0B28:003D CD7C INT 7C
; -t
;
; AX=B800 BX=FFF7 CX=0050 DX=0000 SP=FFFA BP=0000 SI=0052 DI=0782
; DS=0B28 ES=B800 SS=0B28 CS=0000 IP=0200 NV UP DI PL NZ NA PE NC
; 0000:0200 83E901 SUB CX,+01
;
;
;
; * `iret` context in the loop
; AX=B800 BX=FFF7 CX=004F DX=0000 SP=FFFA BP=0000 SI=0052 DI=0782
; DS=0B28 ES=B800 SS=0B28 CS=0000 IP=020C NV UP DI PL NZ AC PE CY
; 0000:020C CF IRET
; -t
;
; AX=B800 BX=FFF7 CX=004F DX=0000 SP=0000 BP=0000 SI=0052 DI=0782
; DS=0B28 ES=B800 SS=0B28 CS=0B28 IP=0036 NV UP EI PL NZ NA PE NC
; 0B28:0036 26 ES:
; 0B28:0037 C60521 MOV BYTE PTR [DI],21 ES:0782=30
;
;
;
; * `iret` context at the end of the loop
; AX=B800 BX=FFF7 CX=0000 DX=0000 SP=FFFA BP=0000 SI=0052 DI=0782
; DS=0B28 ES=B800 SS=0B28 CS=0000 IP=020C NV UP DI PL ZR NA PE NC
; 0000:020C CF IRET
; -t
;
; AX=B800 BX=FFF7 CX=0000 DX=0000 SP=0000 BP=0000 SI=0052 DI=0782
; DS=0B28 ES=B800 SS=0B28 CS=0B28 IP=003F NV UP EI PL NZ NA PE NC
; 0B28:003F 90 NOP
;

assume cs:code
code segment
start: ; Set Up the Interrupt Handler
mov ax,cs
mov ds,ax
mov si,offset do0
mov ax,0
mov es,ax
mov di,200h
mov cx,offset do0end-offset do0
cld
rep movsb
; Set Interrupt Vector Table
mov ax,0
mov es,ax
mov word ptr es:[7ch*4],200h ; offset
mov word ptr es:[7ch*4+2],0 ; segment
; Test the Handler
mov ax,0b800h
mov es,ax
mov di,160*12
mov bx,offset s-offset se
mov cx,80
s: mov byte ptr es:[di],'!'
add di,2
int 7ch
se: nop
mov ax,4c00h
int 21h
; Interrupt Handler Start
do0: sub cx,1
jcxz el
push bp
mov bp,sp
add [bp+2],bx
pop bp
el: iret

do0end: nop

code ends
end start

0 comments on commit 5105165

Please sign in to comment.