cpu 8086 org 0 start: mov ax, 2401h int 15h ; A20 on mov di, 10h mov bx, 0FFFFh mov es, bx ; -> HMA mov ax, 0CCCCh mov cx, (64 * 1024 - 16) / 2 rep stosw ; fill HMA dec bx ; = FFFEh push cs pop ds mov es, bx mov si, code1 mov di, 9B0h mov cx, code1.size rep movsb mov si, code2 mov di, 1A07h mov cx, code2.size rep movsb push cs pop ss mov sp, 0 xor ax, ax mov ds, ax pushf push cs push ax push ds push ax mov dx, i01 int3 xchg word [1 * 4], dx mov word [cs:oldi01], dx mov dx, cs xchg word [1 * 4 + 2], dx mov word [cs:oldi01 + 2], dx mov word [0C6h], 2642h cli pushf pop cx or ch, 1 push cx push bx mov dx, 9B0h push dx iret i01: push bp mov bp, sp push ax push si mov ax, [bp + 2] call disp_ax_hex mov si, msg.1 call disp_cs_si_msg lea ax, [bp + 8] call disp_ax_hex mov si, msg.2 call disp_cs_si_msg mov ax, [bp + 2] cmp ax, 9B0h jb .end cmp ax, 9B0h + code1.size jb .next cmp ax, 1A07h jb .end cmp ax, 1A07h + code2.size jae .end .next: pop si pop ax pop bp iret .end: xor ax, ax mov ds, ax mov ax, word [cs:oldi01] mov word [1 * 4], ax mov ax, word [cs:oldi01 + 2] mov word [1 * 4 + 2], ax int3 xor ax, ax int 16h int 19h disp_cs_si_msg: push si push ax .loop: cs lodsb test al, al jz .end call disp_al jmp .loop .end: pop ax pop si retn disp_ax_hex: xchg al, ah call disp_al_hex xchg al, ah disp_al_hex: push cx mov cl, 4 rol al, cl call .nybble rol al, cl pop cx .nybble: push ax and al, 15 add al, '0' cmp al, '9' jbe .got add al, 7 .got: call disp_al pop ax retn disp_al: push ax push bx push bp mov ah, 0Eh mov bx, 7 int 10h pop bp pop bx pop ax retn code1: .: db 0E8h dw 1054h ; call 1A07h mov ds, ax pop ax cmp ah, 51h db 74h, 0A6h ; jz 0961 cmp ah, 62h db 74h, 0A1h ; jz 0961 cmp ah, 50h db 74h, 96h ; jz 095B cmp ah, 33h .end: .size equ (.end - .) code2: .: push ds mov ax, 0000h mov ds, ax mov ax, [00C6h] pop ds retn .end: .size equ (.end - .) msg: .1: db "h, SP=",0 .2: db "h",13,10,0 absolute $ alignb 2 oldi01: resd 1