Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will write a program in Motorola M68000 assembler that does the following. F

ID: 651756 • Letter: Y

Question

You will write a program in Motorola M68000 assembler that does the following. First, the program will print the programming assignment number, your name, and your class account, all on one line.   Then your program will prompt the user to enter a base 10 number.    Then the program will prompt the user to enter a base to convert the number to.   Finally, your program will print the number converted to the base specified.

Valid numbers to convert are unsigned 16 bit base 10 integers ( 0 .. 65535 ). Valid bases are 2 .. 16.

Digits A-F must be printed in capital letters only.

Your program must validate all input. If the user enters invalid input, you must print a helpful error message, and prompt the user to re-enter the value.

Remember that any time you read input from the keyboard via linein you must have allocated a buffer of at least 80 bytes.

Your answer output line must be all on one line, as in the example.

Remember that all strings you print must be null terminated.

WHAT I HAVE SO FAR:

start: initIO * Initialize (required for I/O)
   setEVT           * Error handling routines
*   initF           * For floating point macros only  
       lineout       title
       lineout       skpln
begin:        lineout       baseTenPrompt
       linein       buffer
       *lineout    baseAnyPrompt
       *linein       buffer
       stripp       buffer,D0
       move.l       D0,D7
       cmpi.l       #5,D7       *D7 is now the stripped buffer
       BHI       lable
       BRA       next
lable:       lineout       error1
       BRA       begin
next:       cmpi.b       #$30,(A1)
       dbra       loop,D7
       cmpi.b       #$39,(A1)
loop:


  


              


break * Terminate execution
*
*----------------------------------------------------------------------
* Storage declarations
title       dc.b    'Program #3, Jonathan Ramos, masc0746',0
skpln:       dc.b   0
error1:       dc.b   'Cannot exceed 5 digits!',0
error2:       dc.b   'Must use digits 0-9!',0
error3:       dc.b   'Must input base 10 number!',0
error4:       dc.b   '
baseTenPrompt:   dc.b   'Enter a base 10 number: ',0
*baseTenInput:   ds.b   20
baseAnyPrompt:   dc.b   'Enter the base to convert to: ',0
*baseAnyInput:   ds.b   20
answer:       dc.b   'The answer is: ',0
buffer:       ds.b   80

              
end

Explanation / Answer

//computer program: converted to base16
//decimal array HEX[]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "sys/types.h"
char Hex [16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
static void readDecimal (int * p, int n, int value);
static int * initHexDecimal (char * p, int * n);
static void printHexDecimal (int * p, int n);

static void readDecimal (int * p, int n, int value)
{
    int carry= value,tmp=0;
    int i;
    for (i = (n-1); (i >= 0); i--)
    {
        tmp = (p[i] * 10) + carry;
        p[i] = tmp % 16;
        carry = tmp / 16;
    }
}
static int * initHexDecimal (char * p, int * n)
{
    int * Array = NULL;
    int l = strlen (p);
    int i;
    Array = (int *) calloc (l, sizeof (int));
    for (i = 0; i < l; i++)
    {
        readDecimal (Array, l, p[i] - '0');
    }
    *n = l;
    return (Array);
}
static void printHexDecimal (int * p, int n)
{
    int a = 0;
    int i;
    while ((p[start] == 0) && (start < (n-1)))
    {
        a++;
    }
    for (i = start; i < n; i++)
    {
        printf ("%c", Hex[p[i]]);
    }
    printf (" ");
}
int main (int argc, char * argv[])
{
    int i;
    int * p = NULL;
    int n;

    if (argc < 2)
    {
        printf ("Array %s decimalString ", argv[0]);
        return (-1);
    }
    p = initHexDecimal (argv[1], &n);
    printHexDecimal (p, n);
    if (p != NULL)
        free (p);
    return (0);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote