How can I fix the middle row to be printed out correctly?

36 Views Asked by At

PROGRAM 4: Rolling Table Using the ROL and ROR instructions, write a program to produce a rolling table. This table should be built from a single int8 value provided by the user and print 3 rows from the starting value, each offset by one from the starting value. In each individual row, the entered number should be ROL'ed and then ROR'ed and then ROL'ed and then ROR'ed, as shown below. For example, the following output should be produced when the user inputs the starting value 4:

Gimme a starting value: 4 Rolling Table 4: 8 2 16 1 5: 10 2 20 1 6: 12 3 24 1

This is my current code program RollingTable; #include ("stdlib.hhf" );

//Declaring Variables

static
value: int8;
num: int8;

begin RollingTable;

//Getting user's input

stdout.put( "Enter an integer value: ");
stdin.get( value );
stdout.put( "Rolling Table",nl);

//first row

stdout.put( value, ":" );
mov(value, ah);
rol(1, ah);
mov(ah, num);
stdout.put( num, " " );
mov(value, ah);
ror(1, ah);
mov(ah, num);
stdout.put( num, " " );
mov(value, ah);
rol(2, ah);
mov(ah, num);
stdout.put( num, " " );
shr(4, ah);
mov(ah, num);
stdout.put ( num, nl );

//Adding 1 to user's input
inc( value );
stdout.put( value, ":" );

//second row
mov(value, ah);
rol(1, ah);
mov(ah, num);
stdout.put( num, " " );
mov(value, ah);
ror(1, ah);
mov(ah, num);
stdout.put( num, " " );
mov(value, ah);
rol(2, ah);
mov(ah, num);
stdout.put( num, " " );
shr(4, ah);
mov(ah, num);
stdout.put ( num, nl );

When I input 4 I get Rolling Table 4: 8 2 16 1 5:10 -126 20 1

I tried rol(0,ah) instead of rol(1,ah) and this was my output

4:8 2 16 1 5:10 5 20 1

0

There are 0 best solutions below