Exemplo n.º 1
0
def Add(num1, num2):
	# Split the two 16 bit input numbers into four 8 bit integers
	num1lo = extract_byte(num1, 'low')
	num1hi = extract_byte(num1, 'high')
	num2lo = extract_byte(num2, 'low')
	num2hi = extract_byte(num2, 'high')
	
	if globals.debug == True:
		print("num1lo: " , num1lo) 
		print("num1hi: " , num1hi << 8) 
		print("num2lo: " , num2lo) 
		print("num2hi: " , num2hi << 8) 
	
	# 6502 Assembly for 16 bit addition
	OP.CLC()			# clear the carry in
	OP.LDA(num1lo)
	cout = OP.ADC(num2lo)
	reslo = OP.STA()	# store sum of LSBs
	if globals.debug == True:
		print("cout1: " , cout)	
	ALU.set_C_IN(cout)
	OP.LDA(num1hi)
	OP.ADC(num2hi)		# add the MSBs using the carry from above
	reshi = OP.STA()	# store sum of MSBs
	cout = ALU.read_C_OUT()
	
	# Debug
	if globals.debug == True:
		print("cout: " , cout)
		print("reslo: " , reslo)
		print("reshi: " , reshi)
	
	# Return result
	return((cout << 16) + (reshi << 8) + reslo)
Exemplo n.º 2
0
def SEC(): # SEt Carry
	ALU.set_C_IN(1)
Exemplo n.º 3
0
def CLC(): # CLear Carry
	ALU.set_C_IN(0)