Mano Basic Computer X*Y and X/Y Code Examples

Posted by dogukanhan on April 15, 2019 · 1 min read

Calculate Positive Numbers X * Y

LDA Y
CMA
INC
STA Y
LDA TOTAL
LOP , 
ADD X
ISZ Y
BUN LOP
STA TOTAL
HLT
X, DEC 10
TOTAL, DEC 0
Y, DEC 10

Calculate Positive Numbers X/Y

LDA Y
CMA
STA Y
LOP , LDA TOTAL
INC
STA TOTAL 
LDA X
ADD Y
STA X
SNA
BUN LOP
HLT
X, DEC 15
Y, DEC 5
TOTAL, DEC 0

Calculate Positive Numbers X^Y

LDA X
STA TOTAL
LDA Y
CMA
INC
INC
STA Y
LOP,
LDA TOTAL
STA TEMP
CLA 
STA TOTAL
LDA TEMP
CMA
INC
STA TEMP
LDA TOTAL
LOP2,
ADD X
ISZ TEMP
BUN LOP2
STA TOTAL
ISZ Y
BUN LOP
STA TOTAL
HLT
X, DEC 10
Y, DEC 3
TOTAL, DEC 0
TEMP, DEC 0

X^Y Java code for better understanting algorithm.

int x = 4;
        int y = 2;
        int total = x;
        for(byte i=0;i<y-1;i++){
            int temp = total;
            total = 0;
            for(byte j=0;j<temp;j++){
                total = total + x;
            }
        }

        System.out.println(total);