Skip to content

Instantly share code, notes, and snippets.

@ahmpro
Created May 4, 2013 10:58
Show Gist options
  • Save ahmpro/5517154 to your computer and use it in GitHub Desktop.
Save ahmpro/5517154 to your computer and use it in GitHub Desktop.
Right division on MCL. (MAI 2013)
writeln "division_6.mcl running";
REG RA[8], RB[8], R1[8], R2[8], R3[8], RC[8];
REG SCH[8], TZ[1], SM[8];
REG INPA[16], INPB[16];
START:
write "A = "; read INPA;
write "B = "; read INPB;
TZ := INPA[15..15] XOR INPB[15..15];
IF INPA[15..15] = 1 THEN INPA := COM INPA;
IF INPB[15..15] = 1 THEN INPB := COM INPB;
RB := INPA[15..8];
R2 := INPA[7..0];
R1 := INPB[7..0];
RA := 0;
SM := RA + RB;
RC := SM SHL 1;
RC[0..0] := R2[7..7];
R3 := R2 SHL 1;
R2 := R3;
RB := RC;
RA := NOT R1;
SM := RA + RB + 1;
RC := SM SHL 1;
RC[0..0] := R2[7..7];
R3 := R2 SHL 1;
R2 := R3;
RB := RC;
IF SM[7..7] = 0 THEN GOTO CANT_DIVISION;
SCH := 7;
loop:
IF SM[7..7] = 1 THEN RA := R1;
IF SM[7..7] = 0 THEN RA := NOT R1;
SM := RA + RB + RA[7..7];
RC := SM SHL 1;
RC[0..0] := R2[7..7];
R3 := R2 SHL 1;
R3[0..0] := NOT SM[7..7];
R2 := R3;
RB := RC;
SCH := SCH - 1;
gosub PRINT_R;
IF SCH <> 0 THEN goto loop;
write "result = ";
IF TZ = 1 THEN write "-";
writeln $D4 R3;
GOTO EXIT;
CANT_DIVISION:
writeln "Can't division";
EXIT:
END;
PRINT_R:
write "R1 = ", $B8 R1; writeln " RB = ", $B8 RB;
write "R2 = ", $B8 R2; writeln " RA = ", $B8 RA;
write "R3 = ", $B8 R3; writeln " SM = ", $B8 SM;
write "RC = ", $B8 RC; writeln " SCH = ", $B8 SCH;
writeln "TZ = ", $B8 TZ;
writeln "---*---*---";
RETURN;
END;
RETURN;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment