# What is the Source Language for a Mini-Calculator?

I have been using the program AsmIDE and the Dragon12P to creat the code. Need help to create a mini calculator in a ".asm" file. The inputs are 3-bit binary number and the calculation result is given on 7-segment LEDs in decimal form. The calculator is able to add, subtract, multiply amd divide two 3 bit binary numbers. The 8-dip switches are used as input, the first 3 right switch es the number A, the next 3 right switches are number B. In subtraction, we always find A-B. If the result of subtraction is negative, turn on the decimal point of the significant 7-segment LED digit. In division we always find A/B. If B is zero, "Er" must be shown on the two result 7-segment digits. The 2 left switches are used for mode of calculation: 00-Add, 01-Subtract, 10-Multiply, 11-Divide.

Update:

This is what I have already started with:

;

;

#include reg9s12.h

org \$2000

VarA rmb 1

VarB rmb 1

Result rmb 1

org \$2010

clr DDRH

ldaa PTH

anda #\$07

staa VarA

ldaa PTH

lsra

lsra

lsra

anda #\$07

staa VarB

ldab PTH

andb #%11000000 ; \$C0

cmpb #0

cmpb #%01000000

beq Subtract

cmpb #%10000000

beq Multy

Divide:

jmp Out

jmp Out

Subtract:

jmp Out

Multy:

Out:

Relevance

Well problem 1 is that you don't even have the assembly instruction set! Every assembly language is different. For example, the "branch if equal" statement in MIPS, "beq", takes 2 arguments because there isn't a "stored" argument (except for floating point numbers and multiplication).

For the Dragon12p, it uses the HCS12 instruction set, which you can find here:

http://www.software-engineer-training.com/computer...

That's a partial set obviously but it contains the functions you need. If you go to that site and skip down to the "addition and subtraction" functions, you'll find things like "ADCA", which stands for "Add with Carry and store in A". Just be careful to keep track of the carry bit.

For multiplication, you can just use addition and a loop. Just remember to copy B into another variable, so you have one copy you can decrement, and one for doing math. Looping involves making a label, doing work, using cmp to check a condition, a beq #0 statement to check the condition (you have an example as to how to do this), and a jmp to the label.

An interesting problem to you once you've done all that would be to figure out how division would work. One way to do it would be to learn bit shifting operations. I'm not sure if HCS12 supports bit shifting but it would be fun to find out.