diff --git a/Gen.pas b/Gen.pas index 78a9457..2844285 100644 --- a/Gen.pas +++ b/Gen.pas @@ -1251,15 +1251,23 @@ else if op^.q in [ubyteToLong,ubyteToUlong,uwordToLong,uwordToUlong] then GenImplied(m_pha); end; {else} end {else if} -else if op^.q in [wordToByte,wordToUbyte,uwordToByte,uwordToUbyte] then +else if op^.q in [wordToUbyte,uwordToUbyte] then GenNative(m_and_imm, immediate, $00FF, nil, 0) +else if op^.q in [wordToByte,uwordToByte] then begin + lab1 := GenLabel; + GenNative(m_and_imm, immediate, $00FF, nil, 0); + GenNative(m_bit_imm, immediate, $0080, nil, 0); + GenNative(m_beq, relative, lab1, nil, 0); + GenNative(m_ora_imm, immediate, $FF00, nil, 0); + GenLab(lab1); + end {else if} else if op^.q in [byteToReal,uByteToReal,wordToReal] then GenCall(11) else if op^.q = uwordToReal then begin GenNative(m_ldx_imm, immediate, 0, nil, 0); GenCall(12); end {else if} -else if op^.q in [longToByte,longToUbyte,ulongToByte,ulongToUbyte] then begin +else if op^.q in [longToUbyte,ulongToUbyte] then begin if gLong.where = A_X then GenNative(m_and_imm, immediate, $00FF, nil, 0) else if gLong.where = constant then @@ -1270,6 +1278,22 @@ else if op^.q in [longToByte,longToUbyte,ulongToByte,ulongToUbyte] then begin GenNative(m_and_imm, immediate, $00FF, nil, 0); end; {else if} end {else if} +else if op^.q in [longToByte,ulongToByte] then begin + if gLong.where = A_X then + GenNative(m_and_imm, immediate, $00FF, nil, 0) + else if gLong.where = constant then + GenNative(m_lda_imm, immediate, long(gLong.lval).lsw & $00FF, nil, 0) + else {if gLong.where = onStack then} begin + GenImplied(m_pla); + GenImplied(m_plx); + GenNative(m_and_imm, immediate, $00FF, nil, 0); + end; {else if} + lab1 := GenLabel; + GenNative(m_bit_imm, immediate, $0080, nil, 0); + GenNative(m_beq, relative, lab1, nil, 0); + GenNative(m_ora_imm, immediate, $FF00, nil, 0); + GenLab(lab1); + end {else if} else if op^.q in [longToWord,longToUword,ulongToWord,ulongToUword] then begin {Note: if the result is in A_X, no further action is needed} if gLong.where = constant then @@ -1983,8 +2007,16 @@ case op^.optype of GenNative(m_rep, immediate, 32, nil, 0); end; {else} if not skipLoad then - if short then + if short then begin GenNative(m_and_imm, immediate, $00FF, nil, 0); + if op^.optype = cgByte then begin + GenNative(m_bit_imm, immediate, $0080, nil, 0); + lab1 := GenLabel; + GenNative(m_beq, relative, lab1, nil, 0); + GenNative(m_ora_imm, immediate, $FF00, nil, 0); + GenLab(lab1); + end; {if} + end; {if} end; {case cgByte,cgUByte,cgWord,cgUWord} otherwise: @@ -3225,6 +3257,7 @@ var simple: boolean; {is the load a simple load?} lLong: longType; {address record for left node} zero: boolean; {is the operand a constant zero?} + lab1: integer; {label} procedure LoadLSW; @@ -3538,8 +3571,16 @@ case optype of end; {else} if short then begin GenNative(m_rep, immediate, 32, nil, 0); - if opcode = pc_cpi then + if opcode = pc_cpi then begin GenNative(m_and_imm, immediate, $00FF, nil, 0); + if optype = cgByte then begin + GenNative(m_bit_imm, immediate, $0080, nil, 0); + lab1 := GenLabel; + GenNative(m_beq, relative, lab1, nil, 0); + GenNative(m_ora_imm, immediate, $FF00, nil, 0); + GenLab(lab1); + end; {if} + end; {if} end; {if} end; {case cgByte,cgUByte,cgWord,cgUWord} @@ -5124,6 +5165,7 @@ procedure GenTree {op: icptr}; var size: integer; {localSize + parameterSize} + lab1: integer; {label} begin {GenRet} {pop the name record} @@ -5172,7 +5214,14 @@ procedure GenTree {op: icptr}; cgByte,cgUByte: begin GenNative(m_lda_dir, direct, funLoc, nil, 0); - GenNative(m_and_imm, immediate, $00FF, nil, 0); + GenNative(m_and_imm, immediate, $00FF, nil, 0); + if op^.optype = cgByte then begin + GenNative(m_bit_imm, immediate, $0080, nil, 0); + lab1 := GenLabel; + GenNative(m_beq, relative, lab1, nil, 0); + GenNative(m_ora_imm, immediate, $FF00, nil, 0); + GenLab(lab1); + end; {if} if size <> 2 then GenImplied(m_tay); end;