CS 3723 Programming Languages
Quadruple Machine

Machine Description: The machine has the following components:

Execution: The machine starts with loc = 0 and executes sequentially except if changed by a jump instruction (see below).

Semantics: Given by the table below. Note that for the arithmetic operators (except for the DIV operation), the operands are doubles and produce a double as the result. Since doubles contain exact integers and exact integer arithmetic as a special case, the machine also works with integers. The operator % works on doubles with an integer value in the same way that it would work on ints, but an extra divide operation that truncates to a double with an exact integer value as the result is useful: the DIV operation. Later high-level programs use /% for this operation.

Code Name Quad form Semantics (in C) Description
11 ADD (ADD, arg1, arg2, res) m[res] = m[arg1] + m[arg2]; Add (+)
12 SUB (SUB, arg1, arg2, res) m[res] = m[arg1] - m[arg2]; Subtract (-)
13 MUL (MUL, arg1, arg2, res) m[res] = m[arg1] * m[arg2]; Multiply (*)
14 DIV (DIV, arg1, arg2, res) m[res] = (m[arg1] - m[arg1]%
       m[arg2]) / m[arg2];
Divide integer (/%)
15 MOD (MOD, arg1, arg2, res) m[res] = (int)m[arg1] %
       (int)m[arg2];
Remainder (%)
16 DVD (DVD, arg1, arg2, res) m[res] = m[arg1] / m[arg2]; Divide double (/)
21 ABS (ABS, arg1,  , res) m[res] = abs( m[arg1] ); Absloute Value
22 CHS (CHS, arg1,  , res) m[res] = - m[arg1]; Change sign
31 JMP (JMP,  ,  , res) loc = res; Jump
32 JEQ (JEQ, arg1,  , res) if (m[arg1] == 0) loc = res; Jump equal
33 JNE (JNE, arg1,  , res) if (m[arg1]  != 0) loc = res; Jump not equal
34 JGE (JGE, arg1,  , res) if (m[arg1] >= 0) loc = res; Jump greater equal
35 JGT (JGT, arg1,  , res) if (m[arg1]  >  0) loc = res; Jump greater than
36 JLE (JLE, arg1,  , res) if (m[arg1] <= 0) loc = res; Jump less equal
37 JLT (JLT, arg1,  , res) if (m[arg1]  <  0) loc = res; Jump less than
41 ASG (ASG, arg1,  , res) m[res] = m[arg1]; Assignment
55 WRC (WRC, arg1,  ,  ) printf("%c", (int)m[arg1]); Write char
56 WRI (WRI, arg1,  ,  ) printf("%d", m[arg1]); Write number
57 RDM (RDM,  ,  , arg1) scanf("%d", &m[arg1]); Read
61 HLT (HLT,  ,  ,  ) exit(0); Halt execution
81 LIT (LIT, arg1,  , res) m[res] = (double)arg1; Literal
91 NOP (NOP,  ,  ,  ) /* */ No-op, do nothing
99 DMP (DMP,  ,  ,  ) Dump  Dump machine state


Revision date: 2001-01-23. (Please use ISO 8601, the International Standard Date and Time Notation.)