Homework 4 - Structured Programming

Programming Assignment 4 and Hints

A palindrome is a word, phrase or number that is the same forward and backward. For example, 1221 is a palindrome but 122 is not palindrome.
  1. Although there are simpler algorithms, please use the algorithm below for determining whether a number is a palindrome.
  2. Write the Assembly language program using structured techniques discussed in class to determine if a given unsigned 32-bit integer is a palindrome.
  3. Document your program following the examples given in class or from the text of Chapter 4.
  4. Turn in
    1. Cover Page - Your name, date, and Homework 4. Staple all pages together.
    2. Assembler program (what you typed in).
    3. Input: 1234, 1221, 12321, 43234, 65456, 214747412, 2147483647, 0. The 0 input terminates the program.
    4. Output: Print whether input number is a palindrome or not a palindrome with the exception of the 0.
Hints

Assembling at IUS

  1. Download io.obj
  2. u:\user\c335\assembler32
  3. ml /coff /Zi /Fl Hw4.asm /link io.obj /subsystem:console
  4. Hw4

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 u:\user\c335\masm32\include\kernel32.inc
   include u:\user\c335\masm32\include\masm32.inc
   includelib u:\user\c335\masm32\lib\kernel32.lib
   includelib u:\user\c335\masm32\lib\masm32.lib
.list

   PutStrng   proto

.code
    Remainder of your program

Pascal Algorithm

{ 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); 
}


Using Visual Studio Debugger with Assembler

The Visual Studio debugger can be used to debug 32-bit Assembler executable programs.

  1. Start Visual Studio .NET
  2. File | Open | Project
  3. HelloWorld.exe
  4. Press F10 key to open the HelloWorld.asm file and start execution.
  5. Save the solution. Required before .NET will continue.
  6. In the figure at right, the arrow point to the next instruction to execute. Passing the mouse pointer over eCx in the assembly code displays the value of eCx=11.
Execute Stop - Necessary before assembling the program again. Debug Commands
Document last modified: