Trending News
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.
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
beq Adder
cmpb #%01000000
beq Subtract
cmpb #%10000000
beq Multy
Divide:
jmp Out
Adder:
jmp Out
Subtract:
jmp Out
Multy:
Out:
3 Answers
- Just JessLv 78 years agoFavorite Answer
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.
- 5 years ago
Here is the program: /*Written by using Arun a.Okay.A The Knight*/ /*Work ; Calculator with features */ /*Interface : Command Line */ /*aspects : Addition , Subtraction , Multiplication , DIvision */ #incorporate<stdio.H> /*operate for Addition*/ add(int a,int b) clrscr(); c=a+b; return(c); /*operate for Subtraction*/ sub(int a,int b); clrscr(); c=a-b; return(c); /*function for Multiplication*/ mul(int a,int b) clrscr(); c=a*b; return(c); /*perform for Division*/ div(int a,int b) clrscr(); c=a/b; return(c): /*operate major*/ primary() int alternative,n1,n2,ans; clrscr(); printf("Please decide upon : n"); printf("1.Additionn2.Subtractionn3.M... Scanf("%d",choice); printf("nPlease enter First number for Calculation : "); scanf("%d",n1); printf("nEnter the 2d number for Calculation : "); if(choice==1) ans=add(n1,n2); printf("The reply is :%d",ans); else if(choice==2) ans=sub(n1,n2); printf("The answer is :%d",ans); else if(option==3) ans=mul(n1,n2); printf("The reply is :%d",ans); else if(choice==4) ans=div(n1,n2); printf("The reply is :%d",ans); /*If all these will not be chosen*/ else printf("Out Of range"); getch(); [b]I wrote it on my own so plz compile urself and verify if it is right . And i am not sure abt the /n i think . Plz rectify the error urself . My First reply :)[b]