Lea
eDi, Palindrome
Mov eCx, 12
Call PutStrng
Assembling at IUS
Suggestions
The listing file (e.g. hw4.lst) can be very large due to the include statements needed for masm32 and Windows functions. The listing size can be significantly reduced by turning the listing off for the include and back on for your program. Use the following at the beginning of your program:
.386 .model flat, stdcall .xcref .nolist include v:\common\user\c335\masm32\include\kernel32.inc include v:\common\user\c335\masm32\include\masm32.inc includelib v:\common\user\c335\masm32\lib\kernel32.lib includelib v:\common\user\c335\masm32\lib\masm32.lib .list PutStrng proto .code Remainder of your program
{ Input integer and determine if a palindrome until 0 entered }
Var AB, BA : Integer; { Numbers
to test if palindromes }
Q :
Integer; { Quotient of division
by 10 }
Begin
Repeat
Writeln('Enter unsigned 16-bit integer:');
Read( AB );
If AB > 0 Then
BEGIN
BA := 0;
Q := AB;
While Q <> 0
Do { Reverse AB to BA }
BEGIN
BA := BA * 10; { Shift BA left 1 digit }
BA := BA + Q Mod 10;{ Right digit of Q = left BA }
Q := Q Div 10; { Drop right digit }
END;
If AB=BA
Then { If
Reversal = Forward }
Writeln('Palindrome') { Then
Palindrome }
Else Writeln('Not
Palindrome');
END;
Until AB = 0;
End.
C++ Algorithm
// Input integer and determine if a palindrome until 0 entered
#include <iostream.h>
void main () {
int AB,
BA; // Numbers to
test if palindromes
int
Q;
// Quotient of division by 10
do {
cout << "Enter unsigned 16-bit
integer:";
cin >> AB;
if (AB > 0) {
BA = 0;
Q = AB;
while ( Q != 0 )
{ // Reverse
AB to BA
BA = BA *
10; //
Shift BA left 1 digit
BA = BA + Q %
10; // Right digit of Q = left
BA
Q = Q /
10;
// Drop right digit
}
if
(AB==BA)
// If Reversal == Forward
cout <<
"Palindrome\n"; // Then Palindrome
else cout << "Not
Palindrome\n";// Else Not Palidrome
}
} while (AB != 0);
}
The
Visual Studio debugger can be used to debug 32-bit Assembler executable programs.
