Jump anywhere: Difference between revisions

m
→‎{{header|TXR}}: Fixed unfinished </code> tag
m (→‎{{header|TXR}}: Fixed unfinished </code> tag)
 
(6 intermediate revisions by 5 users not shown)
Line 201:
 
Although <code>JMP</code> was referred to as "unconditional" before, it does ''not'' have access to the entire address space of the CPU, unlike the 6502, Z80, and 68000. The 8086 uses a segmented memory model, where it uses 20-bit addresses despite being a 16-bit CPU. The other 4 bits are the "segment," and a <code>JMP</code> or <code>CALL</code> cannot exit that segment.
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program julpanaywhere64.s */
 
/************************************/
/* Constantes */
/************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessResult: .asciz "loop indice : "
szMessage1: .asciz "Display to routine call by register\n"
szMessage2: .asciz "Equal to zero.\n"
szMessage3: .asciz "Not equal to zero.\n"
szMessage4: .asciz "loop start\n"
szMessage5: .asciz "No executed.\n"
szMessResult1: .asciz ","
szMessResult2: .asciz "]\n"
szMessStart: .asciz "Program 64 bits start.\n"
szCarriageReturn: .asciz "\n"
 
 
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: // entry of program
ldr x0,qAdrszMessStart
bl affichageMess // branch and link to routine
// return here after routine execution
b label1 // branch unconditional to label
ldr x0,qAdrszMessage5 // this instruction is never executed
bl affichageMess // and this
label1:
ldr x0,qAdrszMessage4
bl affichageMess
mov x20,0
1:
mov x0,x20
ldr x1,qAdrsZoneConv
bl conversion10 // decimal conversion
strb wzr,[x1,x0]
mov x0,#3 // number string to display
ldr x1,qAdrszMessResult
ldr x2,qAdrsZoneConv // insert conversion in message
ldr x3,qAdrszCarriageReturn
bl displayStrings // display message
add x20,x20,1 // increment indice
cmp x20,5
blt 1b // branch for loop if lower
mov x0,0
cbz x0,2f // jump to label 2 if x0 = 0
2:
adr x1,affichageMess // load routine address in register
ldr x0,qAdrszMessage1
blr x1
mov x4,4
cmp x4,10
bgt 3f // branch if higter
mov x0,x4
3:
mov x0,0b100 // 1 -> bit 2
tbz x0,2,labzero // if bit 2 equal 0 jump to label
ldr x0,qAdrszMessage3 // bit 2 <> 0
bl affichageMess
b endtest // jump end if else
labzero: // display if bit equal to 0
ldr x0,qAdrszMessage2
bl affichageMess
endtest:
mov x0,0b000 // 0 -> bit 2
tbnz x0,2,4f // if bit 2 <> 0 jump to label
ldr x0,qAdrszMessage2 // bit 2 = 0
bl affichageMess
b 5f // jump end test
4: // display if bit equal to 1
ldr x0,qAdrszMessage3
bl affichageMess
5:
 
100: // standard end of the program
mov x0, #0 // return code
mov x8,EXIT
svc #0 // perform the system call
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrsZoneConv: .quad sZoneConv
qAdrszMessResult: .quad szMessResult
qAdrszMessage1: .quad szMessage1
qAdrszMessage2: .quad szMessage2
qAdrszMessage3: .quad szMessage3
qAdrszMessage4: .quad szMessage4
qAdrszMessage5: .quad szMessage5
qAdrszMessStart: .quad szMessStart
 
/***************************************************/
/* display multi strings */
/***************************************************/
/* x0 contains number strings address */
/* x1 address string1 */
/* x2 address string2 */
/* x3 address string3 */
/* other address on the stack */
/* thinck to add number other address * 4 to add to the stack */
displayStrings: // INFO: displayStrings
stp x1,lr,[sp,-16]! // save registers
stp x2,x3,[sp,-16]! // save registers
stp x4,x5,[sp,-16]! // save registers
add fp,sp,#48 // save paraméters address (6 registers saved * 8 bytes)
mov x4,x0 // save strings number
cmp x4,#0 // 0 string -> end
ble 100f // branch to equal or smaller
mov x0,x1 // string 1
bl affichageMess
cmp x4,#1 // number > 1
ble 100f
mov x0,x2
bl affichageMess
cmp x4,#2
ble 100f
mov x0,x3
bl affichageMess
cmp x4,#3
ble 100f
mov x3,#3
sub x2,x4,#4
1: // loop extract address string on stack
ldr x0,[fp,x2,lsl #3]
bl affichageMess
subs x2,x2,#1
bge 1b
100:
ldp x4,x5,[sp],16 // restaur registers
ldp x2,x3,[sp],16 // restaur registers
ldp x1,lr,[sp],16 // restaur registers
ret // return to addtress stored in lr
 
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
{{Out}}
<pre>
Program 64 bits start.
loop start
loop indice : 0
loop indice : 1
loop indice : 2
loop indice : 3
loop indice : 4
Display to routine call by register
Not equal to zero.
Equal to zero.
</pre>
 
=={{header|Ada}}==
Line 362 ⟶ 534:
<syntaxhighlight lang="applesoftbasic">CONT : REM CONTINUE, JUMP BACK TO WHERE THE PROGRAM STOPPED</syntaxhighlight>
 
==={{header|IS-BASICBASIC256}}===
<syntaxhighlight lang="is-basic">10 GOTO 100 ! jump to a specific line
20 RUN 200 ! start the program running from a specific line</syntaxhighlight>
 
==={{header|Run BASIC}}===
<syntaxhighlight lang="runbasic">for i = 1 to 10
if i = 5 then goto [label5]
next i
end
 
[label5]
print i
while i < 10
if i = 6 then goto [label6]
i = i + 1
wend
end
 
[label6]
print i
if i = 6 then goto [finish]
print "Why am I here"
 
[finish]
print "done"</syntaxhighlight>
 
=={{header|BASIC256}}==
BASIC256 supports both <code>goto</code> and <code>gosub</code>.
{{works with|QBasic}}
Line 416 ⟶ 562:
{{out}}
<pre>Igual que la entrada de FutureBasic.</pre>
 
==={{header|Chipmunk Basic}}===
Chipmunk Basic supports both <code>goto</code> and <code>gosub</code>.
{{works with|Chipmunk Basic|3.6.4}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">100 CLS
110 PRINT "First line."
120 GOSUB sub1
130 PRINT "Fifth line."
140 GOTO Ending
150 sub1:
160 PRINT "Second line."
170 GOSUB sub2
180 PRINT "Fourth line."
190 RETURN
200 Ending:
210 PRINT "We're just about done..."
220 GOTO Finished
230 sub2:
240 PRINT "Third line."
250 RETURN
260 Finished:
270 PRINT "... with goto and gosub, thankfully."
280 END</syntaxhighlight>
{{out}}
<pre>Same as FutureBasic entry.</pre>
 
==={{header|GW-BASIC}}===
GW-BASIC supports both <code>goto</code> and <code>gosub</code>.
{{works with|Applesoft BASIC}}
{{works with|BASICA}}
{{works with|Chipmunk Basic}}
{{works with|Minimal BASIC}}
{{works with|MSX BASIC|any}}
{{works with|PC-BASIC|any}}
{{works with|QBasic}}
{{works with|Quite BASIC}}
<syntaxhighlight lang="qbasic">100 PRINT "First line."
110 GOSUB 140
120 PRINT "Fifth line."
130 GOTO 190
140 REM sub1:
150 PRINT "Second line."
160 GOSUB 220
170 PRINT "Fourth line."
180 RETURN
190 REM Ending:
200 PRINT "We're just about done..."
210 GOTO 250
220 REM sub2:
230 PRINT "Third line."
240 RETURN
250 REM Finished:
260 PRINT "... with goto and gosub, thankfully."
270 END</syntaxhighlight>
 
==={{header|IS-BASIC}}===
<syntaxhighlight lang="is-basic">10 GOTO 100 ! jump to a specific line
20 RUN 200 ! start the program running from a specific line</syntaxhighlight>
 
==={{header|Minimal BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|MSX Basic}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Quite BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Run BASIC}}===
<syntaxhighlight lang="runbasic">for i = 1 to 10
if i = 5 then goto [label5]
next i
end
 
[label5]
print i
while i < 10
if i = 6 then goto [label6]
i = i + 1
wend
end
 
[label6]
print i
if i = 6 then goto [finish]
print "Why am I here"
 
[finish]
print "done"</syntaxhighlight>
 
==={{header|True BASIC}}===
True BASIC supports both <code>goto</code> and <code>gosub</code>.
<syntaxhighlight lang="qbasic">100 ! Jump anywhere
110 CLEAR
120 PRINT "First line."
130 GOSUB 160
140 PRINT "Fifth line."
150 GOTO 210
160 ! sub1:
170 PRINT "Second line."
180 GOSUB 250
190 PRINT "Fourth line."
200 RETURN
210 ! Ending:
220 PRINT "We're just about done..."
230 GOTO 270
240 ! sub2:
250 PRINT "Third line."
260 RETURN
270 ! Finished:
280 PRINT "... with goto and gosub, thankfully."
290 END</syntaxhighlight>
{{out}}
<pre>Same as FutureBasic entry.</pre>
 
==={{Header|Tiny BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
=={{header|BQN}}==
Line 647 ⟶ 911:
 
=={{header|COBOL}}==
<syntaxhighlight lang="cobolcobolfree"> IDENTIFICATION DIVISION.
PROGRAM-ID. JUMPSjumps-PROGRAMprogram.
* Nobody writes like this, of course; but...
 
PROCEDURE DIVISION.
PROCEDURE DIVISION.
 
* You can jump anywhere you like.
start-paragraph.
START-PARAGRAPH.
GO TO ANan-ARBITRARYarbitrary-PARAGRAPHparagraph.
 
YET-ANOTHER-PARAGRAPH.
yet-another-paragraph.
ALTER START-PARAGRAPH TO PROCEED TO A-PARAGRAPH-SOMEWHERE.
ALTER start-paragraph TO PROCEED TO a-paragraph-somewhere.
* That's right, folks: we don't just have GO TOs, we have GO TOs whose
* destinations can be changed at will, from anywhere in the program,
* at run time.
GO TO STARTstart-PARAGRAPHparagraph.
* But bear in mind: once you get there, the GO TO no longer goes to
* where it says it goes to.
 
A-PARAGRAPH-SOMEWHERE.
a-paragraph-somewhere.
DISPLAY 'Never heard of him.'
DISPLAY 'Never heard of him.'
STOP RUN.
STOP RUN.
SOME-OTHER-PARAGRAPH.
 
some-other-paragraph.
* You think that's bad? You ain't seen nothing.
GO TO YETyet-ANOTHERanother-PARAGRAPHparagraph.
 
AN-ARBITRARY-PARAGRAPH.
an-arbitrary-paragraph.
DISPLAY 'Edsger who now?'
DISPLAY 'Edsger who now?'
GO TO SOME-OTHER-PARAGRAPH.</syntaxhighlight>
GO TO some-other-paragraph.
 
END PROGRAM jumps-program.</syntaxhighlight>
{{out}}
<pre>Edsger who now?
Line 677 ⟶ 949:
'''COBOL''' also supports computed go to phrases, given a list of labels (paragraph names) and an integer index into that list.
 
<syntaxhighlight lang="cobolcobolfree">01 provinceDATA pic 99 value 2DIVISION.
WORKING-STORAGE SECTION.
GO TO quebec, ontario, manitoba DEPENDING ON province</syntaxhighlight>
01 province PICTURE IS 99 VALUE IS 2.
 
PROCEDURE DIVISION.
GO TO quebec, ontario, manitoba DEPENDING ON province.
* Jumps to section or paragraph named 'ontario'.</syntaxhighlight>
 
=={{header|Common Lisp}}==
Line 3,048 ⟶ 3,325:
The above error messages reveal that TXR Lisp's <code>tagbody</code> is implemented by macros, and relies on a dynamic block return. It is provided mainly for compatibility; Common Lisp users using TXR Lisp may find it handy.
 
If the <code>tagbody</code> is still active when the lambda tries to perform a <code>go</code>, it works:
 
<pre>2> (let (fun)
Line 3,199 ⟶ 3,476:
 
The Fiber class also has a ''try'' method for catching errors (which won't be described here) and a static ''abort'' method which (unless caught) exits the script altogether if an error occurs.
<syntaxhighlight lang="ecmascriptwren">var func = Fn.new {
for (i in 1..10) {
if (i == 1) continue // jumps to next iteration when 'i' equals 1
Line 3,237 ⟶ 3,514:
resuming
aborting
[./jumpJump_anywhere line 17] in new(_) block argument
</pre>
 
Line 3,368 ⟶ 3,645:
{{omit from|Oberon-2}}
{{omit from|UNIX Shell|Does not have goto or line labels, but can break from nested loops}}
{{omit from|Insitux}}
9,485

edits