CS220 – Assembly

Computer Organization

Instructor: William Confer, Ph.D.

The code below is for a robot simulation environment we used called ATRobots.

Menu:

Move Test:

; Move Test

!main
        opo     P_THROTTLE,     100     ;set throttle to 100%

!infinite
        jmp     !infinite

Back to Menu

Compass Test:

; Compass Test

#def    delay                                   ; define delay

        mov     delay,          500             ; set delay to 500

!main
        mov     fx,             @1
        call    !err_delay                      ; call err_delay function

;if (@1 is odd) err 1
        mov     ax,             @1
        and     ax,             1

!ift
        cmp     ax,             1
        jne     !ift_end

!ift_true
        mov     fx,             1
        call    !err_delay
!ift_end

;if (@1 < 128) east (2) , else west (3)
!iftf
        cmp     @1,             128
        jls     !iftf_true
!iftf_false
        mov     fx,             3
        call    !err_delay
        jmp     !iftf_end
!iftf_true
        mov     fx,             2
        call    !err_delay
!iftf_end

;while (not west) turn 10 degrees
!while
        cmp     @1,             128
        jge     !while_end
!while_true
        opo     p_steering,     10      ; turn 10 degrees
        jmp     !while
!while_end

; do {turn 10 degrees] while pointing to the west
!dow
        opo     p_steering,     10
        cmp     @1,             128
        jgr     !dow

; if (@1 > 224 || @1 < 32) err (4) else err (5)
!if_north
        cmp     @1,             224
        jgr     !if_north_true
        cmp     @1,             32
        jls     !if_north_true
!if_north_false
        mov     fx,             5
        call    !err_delay
        jmp     !if_north_end
!if_north_true
        mov     fx,             4
        call    !err_delay

!if_north_end
!infinite
        jmp !infinite

; Functions ---------------------------------------------------

; fx contains the number to err
!err_delay
        err     fx
        del     delay                   ; delay the def delay amount
        ret

Back to Menu

Wall Detection:

; Wall Detection

!main
;if(speed == 0) move();
        cmp     @0,     0
        jne     !moving
        opo     P_STEERING,     96
        del     50
        opo     P_THROTTLE,     100     ;set throttle to 100%
!moving

Back to Menu

Wall Detection 2:

; Wall Detection 2

#def    delay                           ; define a constant

        mov     delay,  50              ; move into delay the constant value

!main
; face north
        mov     ax,     @1              ; copy memory location 1 to ax register
        neg     ax                      ; negate ax register
        opo     p_steering,     ax

; move until we stop
        opo     p_throttle,     100     ; set throttle to 100%
!while
        cmp     @0,     0               ; compare memory location @0 to 0
        jne     !while                  ; jump if not equal (jne) back to while

; turn -32 degrees with certainty
        opo     p_steering,     -32     ; turn -32 degrees
        del     100                     ; delay 100 to allow time for turn

; turn 96 degrees, delay and move
        opo     p_steering,     96      ; tun 96 degrees
        del     delay                   ; delay using the constant value delay
        opo     p_throttle,     100     ; set throttle to 100%

; infinite loop
!infinite
        jmp !infinite

;if(speed == 0) move();
        cmp     @0,     0
        jne     !moving
        opo     p_steering,     96      ;turn 96 deg
        del     40                      ;delay 40 to allow time for turn
        opo     p_throttle,     100     ;set throttle to 100%
!moving

Back to Menu

Wall Avoider:

;Ronny L. Bull - Wall Avoider

        opo     p_throttle,     100

!main

        cmp     @0,             0
        je      !stopped
        jmp     !wall_check

!wall_check

        int     i_locate
        cmp     ex,             100
        jls     !stopped
        cmp     fx,             100
        jls     !stopped
        cmp     ex,             900
        jgr     !stopped
        cmp     fx,             900
        jgr     !stopped
        jmp     !main

!stopped

        opo     p_steering,     128     ; turn 128 degrees
        del     100                     ; delay         50
        opo     p_throttle,     100     ; set throttle to 100
        jmp     !main

Back to Menu

Scanning Test:

; Scanning Test

!main
; set scan half circle
        opo     p_arc,  64              ; set scanarc to 64

; for loop 256 times
        mov     ax,     0               ; set ax register to 0
!while
        cmp     ax,     256             ; compare ax regiter to 256
        jge     !while_end              ; jump if greater than or equal to 256 to !while_end

; if robot is scanned, inc array counter
        ipo     p_scan, bx              ; store input from scan port to bx register
!if
        cmp     bx,     1500            ; compare bx to 1500 (length of scanner)
        jgr     !if_end                 ; if bx is greater than 1500 jump to !if_end
!if_true
        mov     cx,     @3              ; store what is in @3 in cx (accuracy value)
        add     cx,     387             ; add the accuracy value stored in cx to 387 (middle of array 0)
        add     [cx],   1               ; add a 1 to what is pointed to by cx
!if_end

        opo     p_trotate,      1       ; turn the turret 1 degree

        add     ax,     1               ; increase ax by 1
        jmp     !while                  ; jump to !while
!while_end

; infinite loop
!infinite
        jmp     !infinite       ; jump to !infinite

Back to Menu

Bot Avoider:

; Bot should not bump into another bot

#config_scanner=0

        opo     p_arc,          64      ; half a half circle scan
        ; mov   ax,             1
        ; int   i_keepshift             

        ; Initialize alpha table
        ; alpha [0] at @387
        ; creating an array of scan arc
        mov     @385,           -56
        mov     @385,           -32
        mov     @385,           0
        mov     @385,           32
        mov     @385,           56

!main
        cmp     @0,             0       ; see if speed is at 0
        jne     !scan

;get_moving
        opo     p_throttle,     -75     ; go reverse
        del     100
        opo     p_steering,     96      ; turn 96 degrees
        del     50
        opo     p_throttle,     100

!scan
        ipo     p_scan,                 ax
        cmp     ax,             1500
        jgr     !no_robot

;robot found!!!!
        ;tabs+180+alpha-abs
        ipo     p_turret_abs,   ax      ; ax = tabs

        mov     fx,             387
        add     fx,             @3
        mov     bx,             [fx]    ; bx = alpha            

        mov     cx,             @1      ; cx = abs

        add     ax,             128
        add     ax,             bx
        sub     ax,             cx

        sar     ax,             1
        opo     p_steering,     ax      ; turn ax degrees
        del     70

        jmp     !main

!no_robot
        opo     p_trotate,      128
        jmp     !main

Back to Menu

Serpentine:

; Ronny Bull (04-15-2010)

;Bot Description: This bot performs a serpentine until it hits a wall, if it hits a wall
;it will escape from the wall, fire an array of shots, lay a mine, then remote detonate it.
;If it hits something more than 5 times the bot will declare itself incompetent, beep a few times, and self destruct.

#config weapon=5
#config scanner=0
#config engine=2
#config armor=3
#config heatsinks=0
#config mines=2

#msg =P
#def    turns                           ; turn counter
#def    spec                            ; special counter

!main

; move until stopped by something
        opo     p_throttle,     100     ; set throttle to 100

; serpentine right
!turn_right
        opo     p_steering,     5       ; turn 5 degrees
        del     5                       ; delay 5
        cmp     @0,             0       ; compare speed to 0
        je      !wall                   ; if equal to 0 jump to !wall
        inc     turns                   ; increase turns by 1
        cmp     turns,          21      ; compare turns to 21
        jle     !turn_right             ; if <= jump to !turn_right
        mov     turns,          0       ; set turns to 0
        jmp     !turn_left              ; jump to !turn_right

; serpentine left
!turn_left
        opo     p_steering,     -5      ; turn 5 degrees
        del     5                       ; delay 5
        cmp     @0,             0       ; compare speed to 0
        je      !wall                   ; if equal to 0 jump to !wall
        inc     turns                   ; increase turns by 1
        cmp     turns,          21      ; compare turns to 21
        jle     !turn_left              ; if <= jump to !turn_left
        mov     turns,          0       ; set turns to 0
        jmp     !turn_right             ; jump to !turn_right

; we hit something!!!
!wall
        opo     p_steering,     96      ; turn 96 degrees
        del     50                      ; delay         50
        opo     p_throttle,     100     ; set throttle to 100

; special moves
!special
        cmp     @0,             0       ; compare @0 to 0
        je      !wall
        opo     15,             0       ; fire straight ahead
        opo     15,             4       ; fire 4 degrees right
        opo     15,             -4      ; fire 4 degrees left
        del     50                      ; delay 50
        opo     22,             1       ; lay a mine
        del     300                     ; delay 300
        opo     23,             1       ; detonate mine
        cmp     spec,           5       ; compare spec to 5
        je      !cya                    ; if 5 jump to !cya
        inc     spec                    ; increase spec by 1
        jmp     !main                   ; jump back to !main

; self destruct gracefully
!cya
        err     10                      ; error 10
        del     100                     ; delay 100
        err     9                       ; error 9
        del     100                     ; delay 100
        err     8                       ; error 8
        del     100                     ; delay 100
        err     7                       ; error 7
        del     100                     ; delay 100
        err     6                       ; error 6
        del     75                      ; delay 75
        err     5                       ; error 5
        del     50                      ; delay 50
        err     4                       ; error 4
        del     35                      ; delay 35
        err     3                       ; error 3
        del     20                      ; delay 20
        err     2                       ; error 2
        del     10                      ; delay 10
        err     1                       ; error 1
        int     0                       ; self destruct

; infinite loop
!infinite
        jmp !infinite

Back to Menu

Follower:

;Ronny Bull - Follower Bot
;Date 4-28-2010
;Bot Description: Bot will attempt to locate and follow another bot in the arena
;The bot will attempt to avoid walls entirely by maintaing 100 meters away.
;Special Move: After counter hits 100 the robot trys to perform a poor attempt
;at the song "Shave and a hair cut, 2 bits" with errors, and exploding on the last note!

#config weapon=0
#config scanner=5
#config engine=5
#config armor=2
#config heatsinks=0
#config mines=0

#msg    =)
#def    spec

        opo     p_arc,          64      ; set scanarc to 64 (half circle)
        opo     p_throttle,     100     ; full speed ahead

!main
        inc     spec                    ; increase spec
        cmp     spec,           100     ; compare spec to 100
        je      !special                ; jump to special if spec = 50
        cmp     @0,             0       ; compare speed to 0
        je      !stopped                ; if not moving deal with it

!wall_check
        int     i_locate                ; get coords
        cmp     ex,             100     ; compare ex to 100 for x
        jls     !stopped                ; jump to !stopped
        cmp     fx,             100     ; compare fx to 100 for y
        jls     !stopped                ; jump to !stopped
        cmp     ex,             900     ; compare ex to 900 for x
        jgr     !stopped                ; jump to !stopped
        cmp     fx,             900     ; compare fx to 900 for y
        jgr     !stopped                ; jump to !stopped

!scanning
        ipo     p_scan,         ax      ; set ax to the value of p_scan
        cmp     ax,             1500    ; compare ax to 1500
        jgr     !get_looking            ; jump to !get_looking

!found_bot
        ipo     p_turret_ofs,   bx      ; set bx to the value of p_turret_ofs
        opo     p_steering,     bx      ; set p_steering to bx
        del     50                      ; delay 50

!get_looking
        opo     p_trotate,      64      ; rotate turret 64 degrees
        jmp     !main                   ; jump to main

!stopped
        opo     p_steering,     96      ; turn 128 degrees
        del     75                      ; delay 75
        opo     p_throttle,     100     ; set throttle to 100
        jmp     !main                   ; jump back to !main

!special
;plays shave and a hair cut - well attempts to that is...
        err     1
        del     80
        err     2
        del     80
        err     3
        del     20
        err     4
        del     40
        err     6
        del     80
        err     7
        del     40
        int     0                       ; self destruct

Back to Menu

Target Practice:

; Ronny L. Bull - Final Exam Extra Credit: Target Practice

#config weapon=4
#config scanner=3
#config engine=0
#config armor=0
#config heatsinks=5
#config mines=0

#msg    Goin' Shootin''

; array
        mov     @385,           -28
        mov     @386,           -14
        mov     @387,           0
        mov     @388,           14
        mov     @389,           28      

!scanning
        opo     p_scanarc,      32      ; set the scanarc to 32
        ipo     p_scan,         ax      ; set ax to the value of p_scan
        cmp     ax,             1500    ; compare ax to 1500
        jle     !bot_found              ; if less than or equal jump to !bot_found
        opo     p_trotate,      64      ; rotate the turret 64 degrees
        jmp     !scanning               ; jump to !scanning

!bot_found
        mov     bx,             @3      ; move into bx the accuracy value from last scan
        add     bx,             387     ; add the value stored in 387 to bx
        opo     p_trotate,      [bx]    ; rotate the turret
        opo     15,             2
        opo     15,             0       ; FIRE!
        opo     15,             -2
        del     60                      ; delay

Back to Menu

Tournament Bot:

; Ronny Bull (04-15-2010)
; Final Tournament Bot
; Bot Description: Bot uses a basic serpentine motion to get around the arena,
; If it hits a wall it turns around and presses on.
; The bot will lay a strip of mines along the area as it serps along
; After a certian amount of time it will remote detonate all of the mines at once
; Bot's Mission: Be the last bot standing!

#config weapon=0
#config scanner=0
#config engine=2
#config armor=5
#config heatsinks=0
#config mines=5

#msg =P
#def    turns                           ; turn counter
#def    boom                            ; mine timer

!main

; move until stopped by something
        opo     p_throttle,     100     ; set throttle to 100

; serpentine right
!turn_right
        opo     p_steering,     5       ; turn 5 degrees
        del     5                       ; delay 5
        cmp     @0,             0       ; compare speed to 0
        je      !stopped                ; if equal to 0 jump to !stopped
        inc     turns                   ; increase turns by 1
        cmp     turns,          21      ; compare turns to 21
        jle     !turn_right             ; if <= jump to !turn_right
        mov     turns,          0       ; set turns to 0
        opo     22,             1       ; lay a mine
        jmp     !turn_left              ; jump to !turn_right

; serpentine left
!turn_left
        opo     p_steering,     -5      ; turn 5 degrees
        del     5                       ; delay 5
        cmp     @0,             0       ; compare speed to 0
        je      !stopped                ; if equal to 0 jump to !stopped
        inc     turns                   ; increase turns by 1
        cmp     turns,          21      ; compare turns to 21
        jle     !turn_left              ; if <= jump to !turn_left
        mov     turns,          0       ; set turns to 0
        opo     22,             1       ; lay a mine
        inc     boom                    ; increase boom
        cmp     boom,           5
        je      !detonate_mines
        jmp     !turn_right             ; jump to !turn_right

; we hit something!!!
!stopped
        opo     p_steering,     96      ; turn 96 degrees
        del     50                      ; delay         50
        opo     p_throttle,     100     ; set throttle to 100

!detonate_mines
        opo     23,             1       ; boom
        jmp     !turn_right

Back to Menu