; LMC Sample Program -IAN! idallen@ncf.ca ; ; A program to output a quotient and a remainder, given a ; divisor and dividend read as input. ; ; C++ high-level statements precede each LMC code block. ; ;Label Mnem. Operand Comments............. ;----- ----- ------- --------------------- ; quot = 0; LDA ZERO ; initialize quotient subtraction counter STO QUOT ; cin >> divor; IN ; read and store divisor (first number) STO DIVOR ; cin >> dend; IN ; read and store dividend (second number) STO DEND ; while ( dend >= divor ) { WHILE LDA DEND ; see if dividend is >= than divisor SUB DIVOR SKP JMP ENDWH ; jump out when dividend < divisor ; dend = dend - divor; LDA DEND ; subtract divisor from dividend SUB DIVOR STO DEND ; quot++; LDA QUOT ; quot counts number of subtractions ADD ONE STO QUOT JMP WHILE ; WHILE loop: keep going until nothing left ; } ; cout << quot; ENDWH LDA QUOT ; output quotient OUT ; cout << dend; LDA DEND ; output remainder OUT HLT ; constants used in this program: ONE DAT 001 ; constant 1 ZERO DAT 000 ; constant 0 ; variables used in this program: DIVOR DAT ? ; int divor; // divisor DEND DAT ? ; int divend; // dividend QUOT DAT ? ; int quot; // quotient