Difference between revisions of "Jasmin/Example"
< Jasmin
Jump to navigation
Jump to search
m |
m |
||
Line 4: | Line 4: | ||
; File: cs/Nano.j | ; File: cs/Nano.j | ||
; Author: Robert Maupin, 3 December 2012 | ; Author: Robert Maupin, 3 December 2012 | ||
− | ; License: | + | ; License: None (use as you like) |
; ------------------------------------------------------------------------- | ; ------------------------------------------------------------------------- | ||
Revision as of 07:07, 14 December 2012
Example of a simple robot written in Jasmin Assembly code.
; --- Copyright Robert Maupin 2012. All rights reserved. -----------------
; File: cs/Nano.j
; Author: Robert Maupin, 3 December 2012
; License: None (use as you like)
; -------------------------------------------------------------------------
; WARNING: you might not ever be able to decompile this class
.class public cs/Nano
.super robocode/AdvancedRobot
; initializer
.method public <init>()V
aload_0
invokenonvirtual robocode/AdvancedRobot/<init>()V
return
.end method
;run method
.method public run()V
;these don't have to be precise, just big enough to hold everything :)
.limit stack 8
.limit locals 8
aload_0 ; the 'this' statement...
;setAdjustGunForRobotTurn(true);
iconst_1
invokevirtual robocode/AdvancedRobot/setAdjustGunForRobotTurn(Z)V
aload_0
;turnRadarRightRadians(1.0/0.0);
dconst_1
dconst_0
ddiv
invokevirtual robocode/AdvancedRobot/turnRadarRightRadians(D)V
return
.end method
;turn onScannedRobot...
.method public onScannedRobot(Lrobocode.ScannedRobotEvent;)V
;these don't have to be precise, just big enough to hold everything
.limit stack 16
.limit locals 8
;if (1 < getOthers())
aload_0
invokevirtual robocode/AdvancedRobot/getOthers()I
iconst_1
;this is 3 bytes.... all jumps are (cept jsr_w, which is 5)
if_icmplt skipInfinityLock
;Infinity Lock Radar
;setTurnRadarLeftRadians(getRadarTurnRemainingRadians());
aload_0
dup
invokevirtual robocode/AdvancedRobot/getRadarTurnRemainingRadians()D
invokevirtual robocode/AdvancedRobot/setTurnRadarLeftRadians(D)V
skipInfinityLock:
return
.end method