Exemplo n.º 1
0
	def transformToAsm(self, containingFunction, containingLoop):
		for instruction in self.left.transformToAsm(containingFunction, containingLoop):
			yield instruction
		for instruction in self.right.transformToAsm(containingFunction, containingLoop):
			yield instruction

		yield Asm('comment', '<')

		carrylabel = nextlabel('lt_carry')
		endlabel = nextlabel('lt_end')

		yield Asm('POP direct', 0) # left
		yield Asm('POP direct', 'ACC') # right

		yield Asm('CLR C')
		yield Asm('SUBB A,Rn', 0) # left - right

		yield Asm('JC rel', carrylabel)

		yield Asm('CLR bit', 'ACC', 0)
		yield Asm('SJMP rel', endlabel)

		yield Asm('label', carrylabel)
		yield Asm('SETB bit', 'ACC', 0)

		yield Asm('label', endlabel)
		yield Asm('PUSH direct', 'ACC')
Exemplo n.º 2
0
	def transformToAsm(self, containingFunction, containingLoop):
		for instruction in self.predicate.transformToAsm(containingFunction, containingLoop):
			yield instruction

		yield Asm('comment', 'if')

		thenlabel = nextlabel('if_then')
		jnbelselabel = nextlabel('if_jnbelse')

		elselabel = nextlabel('if_else')
		endlabel = nextlabel('if_end')

		yield Asm('POP direct', 'ACC')

		yield Asm('JNB bit,rel', 'ACC', 0, jnbelselabel)
		yield Asm('SJMP rel', thenlabel)

		yield Asm('label', jnbelselabel)
		yield Asm('LJMP addr16', elselabel)

		yield Asm('label', thenlabel)

		for instruction in self.then.transformToAsm(containingFunction, containingLoop):
			yield instruction

		yield Asm('LJMP addr16', endlabel)
		yield Asm('label', elselabel)

		for instruction in self.else_.transformToAsm(containingFunction, containingLoop):
			yield instruction
		
		yield Asm('label', endlabel)
Exemplo n.º 3
0
	def transformToAsm(self, containingFunction, containingLoop):
		self.startlabel = nextlabel('while_start')
		self.endlabel = nextlabel('while_end')
		self.jnbcontinuelabel = nextlabel('while_jnbcontinue')
		self.jnbendlabel = nextlabel('while_jnbendlabel')

		yield Asm('comment', 'while')

		yield Asm('label', self.startlabel)

		for instruction in self.condition.transformToAsm(containingFunction, self):
			yield instruction

		yield Asm('POP direct', 'ACC')

		yield Asm('JNB bit,rel', 'ACC', 0, self.jnbendlabel)
		yield Asm('SJMP rel', self.jnbcontinuelabel)

		yield Asm('label', self.jnbendlabel)
		yield Asm('LJMP addr16', self.endlabel)

		yield Asm('label', self.jnbcontinuelabel)

		for instruction in self.body.transformToAsm(containingFunction, self):
			yield instruction

		yield Asm('LJMP addr16', self.startlabel)
		yield Asm('label', self.endlabel)
Exemplo n.º 4
0
	def transformToAsm(self, containingFunction, containingLoop):
		self.startlabel = nextlabel('loop_start')
		self.endlabel = nextlabel('loop_end')

		yield Asm('comment', 'loop')

		yield Asm('label', self.startlabel)

		for instruction in self.body.transformToAsm(containingFunction, self):
			yield instruction

		yield Asm('LJMP addr16', self.startlabel)
		yield Asm('label', self.endlabel)
Exemplo n.º 5
0
	def transformToAsm(self, containingFunction, containingLoop):
		for instruction in self.left.transformToAsm(containingFunction, containingLoop):
			yield instruction
		for instruction in self.right.transformToAsm(containingFunction, containingLoop):
			yield instruction

		yield Asm('POP direct', 'ACC')
		yield Asm('POP direct', 0)

		yield Asm('comment', '!=')

		notequallabel = nextlabel('neq_notequal')
		endlabel = nextlabel('neq_end')

		yield Asm('CJNE A,direct,rel', 0, notequallabel)

		yield Asm('CLR bit', 'ACC', 0)
		yield Asm('SJMP rel', endlabel)

		yield Asm('label', notequallabel)
		yield Asm('SETB bit', 'ACC', 0)

		yield Asm('label', endlabel)
		yield Asm('PUSH direct', 'ACC')
Exemplo n.º 6
0
	def transformToAsm(self, containingFunction, containingLoop):
		self.startlabel = nextlabel('repeat_start')
		self.endlabel = nextlabel('repeat_end')
		self.djnzrepeatlabel = nextlabel('repeat_djnzrepeat')

		yield Asm('comment', 'repeat')

		# save the current repeat counter
		yield Asm('PUSH direct', 1)

		# get the new repeat counter
		for instruction in self.repeatcount.transformToAsm(containingFunction, containingLoop):
			yield instruction

		yield Asm('POP direct', 1)

		# don't execute if the counter is 0
		yield Asm('CJNE Rn,#data,rel', 1, 0, self.startlabel)
		yield Asm('LJMP addr16', self.endlabel)

		# loop
		yield Asm('label', self.startlabel)

		for instruction in self.body.transformToAsm(containingFunction, self):
			yield instruction

		yield Asm('DJNZ Rn,rel', 1, self.djnzrepeatlabel)
		yield Asm('SJMP rel', self.endlabel)

		yield Asm('label', self.djnzrepeatlabel)
		yield Asm('LJMP addr16', self.startlabel)

		yield Asm('label', self.endlabel)

		# restore the old repeat counter
		yield Asm('POP direct', 1)