D
D
DVoropaev2019-01-31 11:48:30
DOS
DVoropaev, 2019-01-31 11:48:30

Why does the program crash with an invalid Opcode error?

The task is this:

Write a DOS resident program (TASM) that sets an interrupt to output "Hi" at 0:1 (0 hours 1 minute)

The program compiles, runs, displays a greeting at the right time, but immediately crashes with an error

Invalid Opcode at 0007 0001 0203 057B 0000 0000 ... 0000

The code is hidden in
spoiler

.model tiny
.code
org 100h
.386
start:jmp load
ASCIInullcolumn db 30h
outchar db ?
cursor db ?
mov cursor, 0
mode db ?
doubledot db 3Ah
old dd 0
;proces
setMode proc near
mov ah, 0Fh
int 10h
mov mode,al
mov ah,00h
mov al,3
int 10h
ret
setMode endp
setCursor proc
pusha
;set cursor
mov ah, 02h
mov bh,0
mov dh,0
mov dl,cursor;êîëóìí
int 10h
popa
ret
setCursor endp
showChar proc
pusha
mov ah,0Ah
mov al, outchar
mov bh,0
mov cx,1
int 10h
popa
ret
showChar endp
showTime proc
pusha
mov cursor,0
call setMode
call setCursor
inc cursor
call setCursor
mov outchar,48h;H
call showChar
inc cursor
call setCursor
mov outchar,69h;i
call showChar
popa
ret
showTime endp
handler:
handler proc near
pushf
call cs:old
push ds
push es
push ax
push bx
push cx
push dx
push di
push cs
pop ds
call showTime
iret
handler endp
end_handler:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;load;;;;;;;;;;;;;;;;;;;;
load:mov ax, 354Ah;35 - number of function, 4A - number of interrupt
int 21h
;setup alarm
mov ch,00h
mov cl,01h
mov dh,0;
mov ah,06h
int 1Ah;
mov word ptr old, bx
mov word ptr old+2,es
mov ax,254Ah
mov dx,offset handler
int 21h
mov ax,3100h
mov dx,(end_handler-start+10Fh)/16
int 21h
ret
end start
. (don't pay attention to the name of the showTime function, it just displays the text. such a name, because in the next revision it should display the time)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question