-4

I´m trying to solve this but I don't know how to start. If someone could give advice how to think about this task it would be great.

hello db "Hello!",0
hello_len equ $-hello 

section .text
start:
; EXERCISE: 
;   TASK: register isr0 for interrupt 0
;   QUESTION: which command triggers an interrupt
cli ; 
;---- fill in your code below ---

;---- fill in your code above ---
sti ; 

; call ISR for interrupt 0 
int 0

; EXERCISE: 
;   TASK:; perform a calculation that triggers interrupt 0 without using the "int" command.
;   QUESTION: why is it looping?
;---- fill in your code below ---

;---- fill in your code above ---

halt: ; stop cpu and wait for interrupts
hlt
jmp halt

isr0:
mov bx,hello
mov cx,hello_len - 1
call output

iret

The output declaration:

push bp       ;
mov bp,sp     ; mov adress from sp to bp 

push bp       ; save current bp
mov bp, bx    ; move string start address to bp 

xor bx, bx    ; bx = 0
mov es, bx    ; es = bx = 0

mov ah, 0x13  ; use function 13h
mov al, 0x01  ; mode 1

mov bl, 0x07  ; color: white
mov bh, 0x00  ; screen page 0

mov dl, 0x00  ; set column
mov dh, [line] ; set line
inc byte [line] ;

int 0x10 

pop bp        ; restore bp

leave  
ret  

section .magic start=(org_address + 510)
db 0x55
db 0xaa
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
neo
  • 1
  • 1
  • 1
    Is this your homework? What did you try, did you execute the code? I would start [reading about interrupts](https://service.scs.carleton.ca/sivarama/asm_book_web/Student_copies/ch12_interrupts.pdf). Then I would write behind each statement what it does - maybe as comment [like here](https://www.tutorialspoint.com/assembly_programming/assembly_basic_syntax.htm) (lookup _mnemonic_ you don't know). – hc_dev Dec 17 '19 at 23:29
  • I don't see declaration of _macro_ `output`. Does the code compile? – hc_dev Dec 17 '19 at 23:37
  • Yes. The Code doesnt execute . I missed the output declaration . Is it possible to repost this Code here ? I´m totally new into this. – neo Dec 18 '19 at 00:10
  • @PeterCordes see https://stackoverflow.com/legal/acceptable-use-policy on how to remove copyrighted content. Please do not vandalise the question in the meantime. – Samuel Liew Dec 19 '19 at 02:13

1 Answers1

3

Interrupt number 0 is the divide exception, #DE. (https://wiki.osdev.org/Interrupt_Vector_Table)

Any integer division where the quotient doesn't fit in the operand-size will raise it. https://www.felixcloutier.com/x86/div or idiv. Or even aam 0 - divide by an immediate zero.

Fun fact: being synchronous, it will still fire when interrupts are disabled. (Although in your template you're only disabling interrupts around modifying the IVT, I guess.)

Fun fact #2: if you were in protected mode, int 0 wouldn't be equivalent to divide by zero. The IDT descriptor applies different privilege level in that case. See Why linux kernel use trap gate to handle divide_error exception? for an example.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Divide by zero throws the exception too. – ecm Dec 18 '19 at 19:44
  • 1
    @ecm: In that case the quotient is infinite, so doesn't fit in any fixed-width base 2 integer. I was intentionally being slightly vague because this is a homework question, and I wanted to encourage the OP to read the manual for `div` where they can see that, too. But my last paragraph does mention divide by zero. – Peter Cordes Dec 18 '19 at 19:47
  • Yeah, and you do mention divide by zero in the second paragraph too, just only in the context of `aam`. I think division by zero is specifically an exception because it is not considered a valid operation, so I find it a bit odd to state "the quotient is infinite". Sure, in some sense it is, but not universally. – ecm Dec 18 '19 at 20:24
  • @ecm: That's just weak justification for being vague on purpose, not much of a real argument. :P – Peter Cordes Dec 18 '19 at 22:26