Question: Write program in HC11 assembly language Write a subroutine to swap the first row of a matrix MAT with the last row, the second row

Write program in HC11 assembly language

Write a subroutine to swap the first row of a matrix MAT with the last row, the second row with the second-to-last row, etc. The matrix MAT is NxM and is stored in row-major order. The starting address of MAT and its dimensions (N and M) are passed to this subroutine in the stack in this order: matrix base address, N, and M (that is, the matrix base address is pushed onto the stack first, followed by N and M). The matrix elements are 8-bit. Write a main program to test this subroutine, including the following features:

1) Call the Buffalo monitor I/O subroutine OUTSTRG to output the message The original matrix is as follows: and call the routine OUTCLRF to move the cursor to the next line.

2) Call the Buffalo monitor I/O subroutines OUTLHLF and OUTRHLF to output the matrix elements, one row per line. Elements should be separated by one space.

3) Call the matrix swap subroutine to swap the rows of the matrix.

4) Call the Buffalo monitor I/O subroutine OUTSTRG to output the message The swapped matrix is as follows: and call the routine OUTCLRF to move the cursor to the next line.

5) Call the Buffalo monitor I/O subroutines OUTLHLF and OUTRHLF to output the elements of the swapped matrix, one row per line. Test your code with a 4x5 matrix that you enter starting at memory location $0100 (your code should work with matrices of any size and not just 4x5). Your main program should be stored in EEPROM starting at memory location $B600. You can check examples 3.4 and 3.5 of your textbook (pages 121- 125) for help on writing your code. Also, a skeleton of the code is shown below in the Program Skeleton section.

Use program skeleton to complete the assignment

N EQU 3 ; Number of matrix rows

M EQU 4 ; Number of matrix columns

OUTA EQU $FFB8 ; Address of OUTA Buffalo subroutine

OUTSTRG EQU $FFC7 ; Address of OUTSTRG Buffalo subroutine

OUTLHLF EQU $FFB2 ; Address of OUTLHLF Buffalo subroutine

OUTRHLF EQU $FFB5 ; Address of OUTRHLF Buffalo subroutine

OUTCRLF EQU $FFC4 ; Address of OUTCRLF Buffalo subroutine

ORG $100

Matrix FCB . . . ; Enter matrix elements here.

FCB . . . ;

FCB . . . ;

FCB . . . ;

. . . ; Allocate memory for variables if needed

ORG $B600 ; Save code in EPROM

**** START OF MAIN PROGRAM ****

Main

LDS #$01FF ; Initialize SP

. . .

LDX #MSG1 ; Load X with base address of MSG1

JSR OUTSTRG ; Call subroutine to print MSG1

. . .

BSR PRINTMAT ;Call subroutine to print original matrix

. . .

BSR SWAPMAT ; Call subroutine to swap matrix columns

. . .

LDX #MSG2 ; Load X with base address of MSG2

JSR OUTSTRG ; Call subroutine to print MSG2

. . .

BSR PRINTMAT ;Call subroutine to print modified matrix

SWI ; return to Buffalo monitor

**** CODE FOR SUBROUTINES GOES HERE ****

PRINTMAT . . . ; code for printing the matrix

. . . ;

RTS ; Return from subroutine

SWAPMAT . . . ; code for swapping the matrix columns

. . . ;

RTS ; Return from subroutine

**** DEFINE MESSAGES ****

MSG1 FCC The original matrix is as follows:, $04

MSG2 FCC The modified matrix is as follows:, $04

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!