Console Input |
L = long register, D = double register
S = string variable
input_l L;
input_d D;
input_s S;
inputch_l L; reads one char and converts to the register type
inputch_d D;
inputch_s S;
The last example showed how to do math and print the result. Now we want to input the numbers which are multiplied. For this we use the "input" opcode:
input_s n;
Writes the input into string variable "n". We convert the string into a number:
val_l n, L0;
Writes the number to register "L0". Now lets put this into the last example:
calc_3.na
1| int x;
2| string n[7];
3|
4| print_s "first number: ";
5| input_s n;
6| val_l n, L0;
7|
8| print_s "second number: ";
9| input_s n;
10| val_l n, L1;
11|
12| mul_l L0, L1, L2;
13| pull_i L2, x;
14|
15| print_l L2;
16| push_i 1, L3;
17| print_n L3;
18|
19| push_i 0, L4;
20| exit L4;
Line 2 declares the string variable "n", which can hold 6 chars. That's enough space for our numbers. Line 4 and 8 prints a text, so we know what data to input here. Line 6 and 10 convert the string into a number. Prev: The Basics | Next: Console Output |