Hi there!
I have a project to do - transformer from Pascal to Assembler, but I've never learned the second language. I want to beg for help everyone, who can helps me. It will be great, if someone can translate to me the code, that I will paste at the end with comments on every row to let me know what is it for. Thank you beforehand!
Sample code:
program E8;
type
MyType=5..10;
var
A: MyType;
B: MyType;
function ReadMyType(X:string):MyType;
var
V: Integer;
begin
Write('Enter type number:');
V := ReadLn(0);
while (V<5) and (V>10) do
begin
WriteLn('ERROR!');
Write('Enter type number:');
V := ReadLn(0);
end;
ReadMyType := V;
end;
begin
A := ReadMyType('A');
B := ReadMyType('B');
if A>B then
WriteLn('A is greater!');
if A<B then
WriteLn('B is greater!');
if A=B then
WriteLn('A and B are equal!');
end.
There's a lot more here than simply transforming the code into asm. Also, Pascal compilers don't usually do a direct translation, they create p-code for the Pascal virtual machine; this would also reduce how much asm you need to write/understand (if any - you can make the Pascal machine in any language.) Or you could write a p-code interpreter, which would also be easier than trying to write a full Pascal-asm compiler.
If this is homework, it seems like a lot to do in one go.
I think the assignment is to translate this example into an equivalent assembler example, not write a compiler to do it. Pseudo code in Pascal if you will.
Most of my old Pascal compilers choke on this code, but check if your compiler is capable of generating assembler listings, or interleaved source/assembler, this might provide you with an equivalence you can learn from. Most C compilers are capable of doing this, so if your Pascal one doesn't try a C one.
You could also try JJ's MasmBasic which might provide a simpler transition, especially with the input/output of numbers. Register level numeric comparisons are something covered in any book on assembler.
Thank you about the advises! :clap: