Halt and catch fire: Difference between revisions

From Rosetta Code
Content added Content deleted
(Added Go)
(→‎{{header|Go}}: Replaced with a line which actually builds!)
Line 48: Line 48:
The output depends on the compiler and platform but should be similar.
The output depends on the compiler and platform but should be similar.
=={{header|Go}}==
=={{header|Go}}==
<lang go>package main; import "fmt"; func main(){fmt.Println(0/0)}</lang>
<lang>package main; import "fmt"; func main(){a, b := 0, 0; fmt.Println(a/b)}</lang>


=={{header|Pascal}}==
=={{header|Pascal}}==

Revision as of 08:56, 13 September 2021

Task
Halt and catch fire
You are encouraged to solve this task according to the task description, using any language you may know.
Task

Create a program that crashes as soon as possible, with as few lines of code as possible. Be smart and don't damage your computer, ok?

References
  1. Halt and Catch Fire



6502 Assembly

Upon executing this byte as code, the processor will halt. No interrupts can occur either. This does not occur on 65c02-based hardware such as the Apple II or Atari Lynx. <lang 6502asm> db $02</lang>

8086 Assembly

Translation of: Z80 Assembly

Disabling interrupts prior to a HLT command will cause the CPU to wait forever. <lang asm>cli hlt</lang>

68000 Assembly

The 68000 can only read words or longs at even addresses. Attempting to do so at an odd address will crash the CPU. <lang 68000devpac>CrashBandicoot equ $100001 LEA CrashBandicoot,A0 MOVE.W (A0),D0</lang>

ALGOL 68

This program will crash immediately on startup. <lang algol68>( print( ( 1 OVER 0 ) ) )</lang>

ALGOL W

This won't halt the CPU but the program will crash immediately on startup. <lang algolw>assert false.</lang>

C++

Use an unhandled exception to crash the program. <lang cpp>#include <stdexcept> int main() {

   throw std::runtime_error("boom");

}</lang>

Output:
terminate called after throwing an instance of 'std::runtime_error'
  what():  boom

The output depends on the compiler and platform but should be similar.

Go

<lang>package main; import "fmt"; func main(){a, b := 0, 0; fmt.Println(a/b)}</lang>

Pascal

Works with: Free Pascal

Do an illegal memory access at $0

<lang pascal>begin pByte($0)^ := 0 end.</lang>

Output:
Runtime error 216 at $0000000000401098

Perl

<lang perl>&a</lang>

Output:
Undefined subroutine &main::a called at line 1.

Raku

<lang perl6>++8</lang> Syntactically: Valid.

Semantically: Change the mathematical concept of 8 to 9, either in your whole computer, or maybe the whole universe.

Fails with this run-time error:

Output:
Cannot resolve caller prefix:<++>(Int:D); the following candidates
match the type but require mutable arguments:
    (Mu:D $a is rw)
    (Int:D $a is rw --> Int:D)

The following do not match for other reasons:
    (Bool $a is rw)
    (Mu:U $a is rw)
    (Num:D $a is rw)
    (Num:U $a is rw)
    (int $a is rw --> int)
    (num $a is rw --> num)
  in block <unit> at -e line 1

REXX

<lang rexx>=</lang>

Wren

<lang ecmascript>Fiber.abort("")</lang>

Z80 Assembly

The processor is permanently halted. Strangely enough, this does not work on the Game Boy. Rather, both the HALT instruction and the instruction after it are skipped. <lang z80>di halt</lang>