def _shl16(ins): ''' Logical/aritmetical left shift 16bit (un)signed integer. The result is pushed onto the stack. Optimizations: * If 2nd op is 0 then do nothing * If 2nd op is lower than 6 unroll lop ''' op1, op2 = tuple(ins.quad[2:]) if is_int(op2): op = int16(op2) if op == 0: return [] output = _16bit_oper(op1) if op < 6: output.extend(['add hl, hl'] * op) output.append('push hl') return output output.append('ld b, %i' % op) else: output = _8bit_oper(op2) output.append('ld b, a') output.extend(_16bit_oper(op1)) label = tmp_label() output.append('%s:' % label) output.append('add hl, hl') output.append('djnz %s' % label) output.append('push hl') return output
def _shl32(ins): ''' Logical Left shift 32bit unsigned integers. The result is pushed onto the stack. Optimizations: * If 2nd operand is 0, do nothing ''' op1, op2 = tuple(ins.quad[2:]) if is_int(op2): output = _32bit_oper(op1) if int(op2) == 0: output.append('push de') output.append('push hl') return output if int(op2) > 1: label = tmp_label() output.append('ld b, %s' % op2) output.append('%s:' % label) output.append('call __SHL32') output.append('djnz %s' % label) else: output.append('call __SHL32') output.append('push de') output.append('push hl') REQUIRES.add('shl32.asm') return output output = _8bit_oper(op2) output.append('ld b, a') output.extend(_32bit_oper(op1)) label = tmp_label() output.append('%s:' % label) output.append('call __SHL32') output.append('djnz %s' % label) output.append('push de') output.append('push hl') REQUIRES.add('shl32.asm') return output
def _shri16(ins): ''' Arithmetical right shift 16bit signed integer. The result is pushed onto the stack. Optimizations: * If 2nd op is 0 then do nothing * If 2nd op is 1 Shift Right Arithmetic ''' op1, op2 = tuple(ins.quad[2:]) if is_int(op2): op = int16(op2) if op == 0: return [] output = _16bit_oper(op1) if op == 1: output.append('srl h') output.append('rr l') output.append('push hl') return output output.append('ld b, %i' % op) else: output = _8bit_oper(op2) output.append('ld b, a') output.extend(_16bit_oper(op1)) label = tmp_label() output.append('%s:' % label) output.append('sra h') output.append('rr l') output.append('djnz %s' % label) output.append('push hl') return output
def _pstore8(ins): ''' Stores 2nd parameter at stack pointer (SP) + X, being X 1st parameter. 1st operand must be a SIGNED integer. ''' value = ins.quad[2] offset = ins.quad[1] indirect = offset[0] == '*' size = 0 if indirect: offset = offset[1:] size = 1 I = int(offset) if I >= 0: I += 4 # Return Address + "push IX" if not indirect: I += 1 # F flag ignored if is_int(value): output = [] else: output = _8bit_oper(value) ix_changed = not (-128 + size <= I <= 127 - size) # Offset > 127 bytes. Need to change IX if ix_changed: # more than 1 byte output.append('push ix') output.append('pop hl') output.append('ld de, %i' % I) output.append('add hl, de') if indirect: if ix_changed: output.append('ld c, (hl)') output.append('inc hl') output.append('ld h, (hl)') output.append('ld l, c') else: output.append('ld h, (ix%+i)' % (I + 1)) output.append('ld l, (ix%+i)' % I) if is_int(value): output.append('ld (hl), %i' % int8(value)) else: output.append('ld (hl), a') return output # direct store if ix_changed: if is_int(value): output.append('ld (hl), %i' % int8(value)) else: output.append('ld (hl), a') return output if is_int(value): output.append('ld (ix%+i), %i' % (I, int8(value))) else: output.append('ld (ix%+i), a' % I) return output