Commit with mistake
This commit is contained in:
BIN
programs/nja
BIN
programs/nja
Binary file not shown.
61
programs/prog4.asm
Normal file
61
programs/prog4.asm
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// prog1.asm -- an assembler example with global variables
|
||||
//
|
||||
|
||||
//
|
||||
// compute the gcd of two positive numbers
|
||||
//
|
||||
// global Integer x;
|
||||
// global Integer y;
|
||||
// x = readInteger();
|
||||
// y = readInteger();
|
||||
// while (x != y) {
|
||||
// if (x > y) {
|
||||
// x = x - y;
|
||||
// } else {
|
||||
// y = y - x;
|
||||
// }
|
||||
// }
|
||||
// writeInteger(x);
|
||||
// writeCharacter('\n');
|
||||
|
||||
// x = readInteger();
|
||||
rdint
|
||||
popg 0
|
||||
// y = readInteger();
|
||||
rdint
|
||||
popg 1
|
||||
// while ...
|
||||
L1:
|
||||
// x != y
|
||||
pushg 0
|
||||
pushg 1
|
||||
ne
|
||||
brf L2
|
||||
// if ...
|
||||
pushg 0
|
||||
pushg 1
|
||||
gt
|
||||
brf L3
|
||||
// x = x - y
|
||||
pushg 0
|
||||
pushg 1
|
||||
sub
|
||||
popg 0
|
||||
jmp L4
|
||||
L3:
|
||||
// y = y - x
|
||||
pushg 1
|
||||
pushg 0
|
||||
sub
|
||||
popg 1
|
||||
L4:
|
||||
jmp L1
|
||||
L2:
|
||||
// writeInteger(x);
|
||||
pushg 0
|
||||
wrint
|
||||
// writeCharacter('\n');
|
||||
pushc '\n'
|
||||
wrchr
|
||||
halt
|
||||
BIN
programs/prog4.bin
Normal file
BIN
programs/prog4.bin
Normal file
Binary file not shown.
63
programs/prog5.asm
Normal file
63
programs/prog5.asm
Normal file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// prog2.asm -- an assembler example with local variables
|
||||
//
|
||||
|
||||
//
|
||||
// compute the gcd of two positive numbers
|
||||
//
|
||||
// local Integer x;
|
||||
// local Integer y;
|
||||
// x = readInteger();
|
||||
// y = readInteger();
|
||||
// while (x != y) {
|
||||
// if (x > y) {
|
||||
// x = x - y;
|
||||
// } else {
|
||||
// y = y - x;
|
||||
// }
|
||||
// }
|
||||
// writeInteger(x);
|
||||
// writeCharacter('\n');
|
||||
|
||||
asf 2
|
||||
// x = readInteger();
|
||||
rdint
|
||||
popl 0
|
||||
// y = readInteger();
|
||||
rdint
|
||||
popl 1
|
||||
// while ...
|
||||
L1:
|
||||
// x != y
|
||||
pushl 0
|
||||
pushl 1
|
||||
ne
|
||||
brf L2
|
||||
// if ...
|
||||
pushl 0
|
||||
pushl 1
|
||||
gt
|
||||
brf L3
|
||||
// x = x - y
|
||||
pushl 0
|
||||
pushl 1
|
||||
sub
|
||||
popl 0
|
||||
jmp L4
|
||||
L3:
|
||||
// y = y - x
|
||||
pushl 1
|
||||
pushl 0
|
||||
sub
|
||||
popl 1
|
||||
L4:
|
||||
jmp L1
|
||||
L2:
|
||||
// writeInteger(x);
|
||||
pushl 0
|
||||
wrint
|
||||
// writeCharacter('\n');
|
||||
pushc '\n'
|
||||
wrchr
|
||||
rsf
|
||||
halt
|
||||
BIN
programs/prog5.bin
Normal file
BIN
programs/prog5.bin
Normal file
Binary file not shown.
61
programs/prog6.asm
Normal file
61
programs/prog6.asm
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// prog1.asm -- an assembler example with global variables
|
||||
//
|
||||
|
||||
//
|
||||
// compute the gcd of two positive numbers
|
||||
//
|
||||
// global Integer x;
|
||||
// global Integer y;
|
||||
// x = readInteger();
|
||||
// y = readInteger();
|
||||
// while (x != y) {
|
||||
// if (x > y) {
|
||||
// x = x - y;
|
||||
// } else {
|
||||
// y = y - x;
|
||||
// }
|
||||
// }
|
||||
// writeInteger(x);
|
||||
// writeCharacter('\n');
|
||||
|
||||
// x = readInteger();
|
||||
rdint
|
||||
popg 0
|
||||
// y = readInteger();
|
||||
rdint
|
||||
popg 1
|
||||
// while ...
|
||||
L1:
|
||||
// x != y
|
||||
pushg 0
|
||||
pushg 1
|
||||
ne
|
||||
brf L2
|
||||
// if ...
|
||||
pushg 0
|
||||
pushg 1
|
||||
gt
|
||||
brf L3
|
||||
// x = x - y
|
||||
pushg 0
|
||||
pushg 1
|
||||
sub
|
||||
popg 0
|
||||
jmp L4
|
||||
L3:
|
||||
// y = y - x
|
||||
pushg 1
|
||||
pushg 0
|
||||
sub
|
||||
popg 1
|
||||
L4:
|
||||
jmp L1
|
||||
L2:
|
||||
// writeInteger(x);
|
||||
pushg 0
|
||||
wrint
|
||||
// writeCharacter('\n');
|
||||
pushc '\n'
|
||||
wrchr
|
||||
halt
|
||||
Reference in New Issue
Block a user