Skip to content

Instantly share code, notes, and snippets.

@danwoods
Created November 17, 2010 15:56
Show Gist options
  • Save danwoods/703546 to your computer and use it in GitHub Desktop.
Save danwoods/703546 to your computer and use it in GitHub Desktop.
Check if current number in ACC is negative
;Dan Woodson
;Check if Negatives
JMP _start
; Variables
sentinal: 20 ; range to check for negatives (up to -31)
sent_count: 0 ; temp count
pos_test: 2 ; number to check
register: 0 ; extra reg
neg_flag: 0 ; negative flag (if value in ACC is negative)
orig_value: 0 ; extra reg
;;;Functions;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;Check if Neg;;;
_check_if_neg
; store acc
STOAC register
STOAC orig_value
;setup sentinal and neg_flag (clear)
CLAC
STOAC sent_count
STOAC neg_flag
_begin_neg_loop
; restore value to ACC
LDA register
; increment and see if result equals zero
INC
STOAC register
JMPZ _set_flag
;increment loop count
LDA sent_count
INC
STOAC sent_count
;if sent_count = sentinal: break/return
MOVAC
LDA sentinal
SUB
JMPZ _return_check_if_neg
JMP _begin_neg_loop
_set_flag
INC
STOAC neg_flag
;return
JMP _return_check_if_neg
;;;;;;;;;;;;;;;;;;;;MAIN PROGRAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_start
_main
;setup negative
LDA pos_test
MOVAC
CLAC
SUB
STOAC orig_value
JMP _check_if_neg
_return_check_if_neg
LDA orig_value
;NOW CHECK neg_flag
OUT
HALT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment