Jump to content

Category:68000 Assembly: Difference between revisions

m
Line 102:
This is completely unnecessary, as the <code>DIVU</code> and <code>DIVS</code> use a trap to handle a divide by zero automatically. If the CPU would attempt to divide by zero, the processor automatically calls the relevant trap (Trap 5 in this case). The return address and processor flags are saved, and execution jumps to the address specified in the trap list (a table of pre-defined memory addresses, stored at $000080 and going up. The standard 16 traps are stored here, with a 17th stored at $00001C.
 
===Hardware-Defined Traps===
Certain traps have specific meanings as defined by the 68000 itself:
* Trap 4 occurs if the <code>ILLEGAL</code> command is executed. This is similar to <code>BRK</code> on [[6502 Assembly]]. If you're programming on a system or emulator with no built-in debugger, it's a handy way of seeing if execution is arriving at a certain point. If Trap 4 is pointed to a system reset or a hexdump routine you created, you'll know in an instant if the code before it is bugged. This (admittedly contrived) example will show the basic concept.
Line 121 ⟶ 122:
* The 17th trap is called the "Overflow Trap" and can only be called with the <code>TRAPV</code> instruction, which calls it <i>if the overflow flag is set.</i>
 
===Kernel-Defined Traps===
Depending on the hardware, certain traps are built-in to perform certain tasks, such as reading a keyboard or mouse, or are user-defined. To create your own trap routine, you'll need to first write the routine, then store its address in the corresponding trap number. Trap 0 is stored at $000080, Trap 1 at $000084, and so on. The overflow trap is stored at address $00001C.
 
1,489

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.