Problem: "A big integer is represented as a list of (small) integers."
Suppose to have:
type reg = string;; (* "$0" models register set to constant 0 *)
type label = string;; (* empty string models no label *)
type asmistr =
AsmHalt
| AsmNop
| AsmAdd of reg * reg * reg
| AsmAddi of reg * int * reg
| AsmSub of reg * reg * reg
| AsmMul of reg * reg * reg
| AsmLoad of reg * reg * reg
| AsmStore of reg * reg * reg
| AsmJmp of label
| AsmBne of reg * reg * label
| AsmBeq of reg * reg * label
| AsmSlt of reg * reg * reg
;;
type asmprog = AsmProg of (label * asmistr) list;;
type asmline =
AsmIstr of label * asmistr
| AsmComment of string
| AsmDebugReg of reg
| AsmDebugMem of int * int
;;
This sets of definitions are used for define a language like assembly, using registers, instructions and labels (used on jumps)
Now I need to implement a compiler from a imperative language (that has instructions like "while" "if") to ASM
The implementation suggested by my teacher is to use a list where each element is the digit of the given number (the number can be only integer) like 11000 is [1, 1, 0, 0, 0]
The first gap is: how can I implement this considering a generic O'Caml program? Suppose that I have to insert a big integer, what logic I can use to permit "calculations"? Because at the end, an ASM program can also do add, sub mul and other instruction that can include big integers, so I don't know how to deal this with registers, big integers and instructions
What I need is a general scheme of how to implement big integers, possibly in O'Caml language, and how to realize this considering a language similar to assembly (in this case, ASM)
thanks in advance, if is not clear, sorry for my english and if someone can help me, I will put more details if needed