convert c code to hla int start int amount 1 the delta amo
convert c code to hla:
int start; int amount = 1; /* the delta amount to add to each value as the code loops */
bool negative = true; /* are we adding or subtracting from the delta */
printf( \"Gimme data: \" );
scanf( \"%d\", &start );
int value = start;
for (int i = 1; i <= start; i++)
{
if (i != 1)
{
printf( \"_\" );
}
printf( \"%d\", value );
if (negative)
{
value = value - amount;
}
else
{
value = value + amount;
}
amount = amount + 1;
negative = !negative;
}
printf( \"\ \" );
Solution
program C_to_hla;
#include(\"stdlib.hhf\");
static
nagative:boolean; /*bool negative = true;*/
start:int32:=0; /* int start; int amount = 1; */
amount:int32=1;
value:int32;
begin C_to_hla;
mov(true,nagative);
stdout.put(\"Gimme data\"); /*printf( \"Gimme data: \" ); */
stdin.geti32(); /*scanf( \"%d\", &start );*/
mov(eax,start);
mov(eax,value); /*value = start;*/
for(mov(i,i);i<=start;add(1,i)) do /* for (int i = 1; i <= start; i++) */
if(i!=1) then /* if (i != 1) */
stdout.put(\"--\");
endif;
stdout.put(value);
if(negative) then
mov(value,eax); /*value = value - amount */
sub(amount,eax);
mov(eax,value);
else
mov(value,eax); /* value = value + amount;*/
add(amount,eax);
mov(eax,value);
endif;
add(1,amount); /*amount = amount + 1; */
negative:=!negative; /*negative = !negative;*/
endfor;
stdout.put(n1); /*printf( \"\ \" );*/

