%if 0 Usage of the works is permitted provided that this instrument is retained with the works, so that any entity that uses the works is notified of this instrument. DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. %endif cpu 8086 org 256 start: mov si, 81h .skip: lodsb cmp al, 32 je .skip cmp al, 9 je .skip cmp al, '!' jne .notex not byte [wantfree] .notex: dec si call getnumber init: mov ax, 4300h int 2Fh cmp al, 80h je .gotxms mov dx, msg.noxms jmp errorexit .gotxms: mov ax, 4310h int 2Fh mov word [handler], bx mov word [handler + 2], es rol byte [wantfree], 1 jc free alloc: mov dx, msg.alloc1 call disp_msg mov ax, di call disp_ax_dec mov dx, msg.alloc2 call disp_msg mov dx, di mov ah, 09h push cs call callhandler cmp ax, 1 jne .error push dx mov dx, msg.alloc3 call disp_msg pop ax call disp_ax_dec mov dx, msg.alloc4 call disp_msg mov ax, 4C00h int 21h .error: push dx mov dx, msg.alloc5 call disp_msg mov al, bl call disp_al_hex mov dx, msg.alloc6 call disp_msg pop ax call disp_ax_dec mov dx, msg.alloc7 errorexit: call disp_msg mov ax, 4C01h int 21h free: mov dx, msg.free1 call disp_msg mov ax, di call disp_ax_dec mov dx, msg.free2 call disp_msg mov dx, di mov ah, 0Ah push cs call callhandler cmp ax, 1 jne .error mov dx, msg.free3 call disp_msg mov ax, 4C00h int 21h .error: mov dx, msg.free5 call disp_msg mov al, bl call disp_al_hex mov dx, msg.free6 jmp errorexit disp_msg: push ax mov ah, 09h int 21h pop ax retn disp_ax_dec: push ax push cx push dx mov cx, 10 mov dx, -1 push dx .loop1: xor dx, dx div cx push dx test ax, ax jnz .loop1 .loop2: pop ax add al, '0' jc .end xchg dx, ax mov ah, 02h int 21h jmp .loop2 .end: pop dx pop cx pop ax 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 disp_al_nybble_hex rol al, cl pop cx disp_al_nybble_hex: push ax push dx and al, 15 add al, '0' cmp al, '9' jbe .got add al, 7 .got: xchg dx, ax mov ah, 02h int 21h pop dx pop ax retn callhandler: jmp 0:0 handler equ $ - 4 ; INP: si -> text ; OUT: si - 1 -> end (nondigit) ; di = number getnumber: .skip: lodsb cmp al, 32 je .skip cmp al, 9 je .skip cmp al, '0' jb error cmp al, '9' ja error xor di, di jmp .digit .loop: lodsb .digit: cmp al, '_' je .loop sub al, '0' jb .end cmp al, 10 jae .end cbw add di, di ; times 2 mov bx, di add di, di ; times 4 add di, di ; times 8 add di, bx ; times 10 add di, ax jmp .loop .end: retn error: mov dx, msg.error jmp errorexit wantfree: db 0 msg: .error: db "Error!",13,10,36 .noxms: db "No XMS entry found!",13,10,36 .alloc1: db "Trying to allocate ",36 .alloc2: db " KiB, ",36 .alloc3: db "success, handle=",36 .alloc7: .alloc4: db 13,10,36 .free5: .alloc5: db "error, code=",36 .alloc6: db "h, dx=",36 .free1: db "Trying to free handle=",36 .free2: db ", ",36 .free6: db "h",13,10,36 .free3: db "success",13,10,36