Assertions in design by contract: Difference between revisions

Content added Content deleted
Line 7: Line 7:
Show in the program language of your choice an example of the use of assertions as a form of documentation.
Show in the program language of your choice an example of the use of assertions as a form of documentation.
<br><br>
<br><br>

=={{header|68000 Assembly}}==
Error handlers are referred to as *traps* on the 68000, and they can be triggered automatically (such as attempting to divide by zero) and by command (such as for if overflow has occurred.)

Precondition example:
<lang 68000devpac> DIVU D3,D2 ;this will cause a jump to Trap 4 if D3 = 0.</lang>

Postcondition examples:
<lang 68000devpac> ADD.L D4,D5
TRAPV ;no overflow is expected, so if it occurs call the relevant trap.</lang>

<lang 68000devpac> LSL.W #8,D2 ;shift D2 left 8 bits.
bcc continue ;if carry clear, we're good.
trap 9 ;otherwise call trap 9, which has arbitrarily been defined to handle unexpected carries after a bit shift.

continue: ;the program resumes normally after this point
</lang>




=={{header|Ada}}==
=={{header|Ada}}==