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

Write a program to convert the hexadecimal contents of a block of RAM into print

ID: 2248092 • Letter: W

Question

Write a program to convert the hexadecimal contents of a block of RAM into printable ASCII characters and leave the results in another block of RAM. Each byte in the source block contains two 4-bit hex digits (nibbles) and the printable ASCII characters corresponding to each nibble are 8-bits each therefore each byte from the source block will be converted to two bytes in the result block (known as "ASCII hex". Your program will be in the code section starting at S0000 and you will have three variables that will be in the variableldata section located at S0100: the first variable will contain the 2 byte starting address of the block to be converted, the second will contain the 2-byte starting address of the result block and the third variable will be the 1-byte number of bytes to convert (please define the variables in this order). Your program should include a subroutine to do the conversion of each nibble into its corresponding ASCII code. Note: in order to convert a byte into ASCII hex, you must separate the 8-bit byte into two 4-bit nibbles and then use the ASCII chart below to convert the nibble into an ASCII character Nibble ASC ASCII 1 0001 20010 32 A 1010 41 3 0011 33 42 0300 34C 100 43 0 D 101 60110 30 5 0111 F46 Example conversion: Note: each byte of the source block will convert to two bytes in the result block. Address Source Daa Address Result Data 0x300 0x31 0x301 0N41 0x302 0x46 0x303 0s34 0x200 OxIA 0x201 0F4 You will also simulate sending the converted data to a printer. After each result byte is generated you will send it to an output port and you will generate the required printer control signals using bit banging. The data for the printer will be sent out using Port D (PORTD) and the printer control signals will be sent using Port B (PORTB). There will be two "active low control signals: WRT N, and STB N attached to PB1 and PB0 respectively. The timing diagram below illustrates the relationship between the various signals that you must generate. Notice that in between bytes on Port D, the bus should hold a zero value. In order to initialize WRT N and STB N to the high state, you would write a 0b00000011 to PORTB, and then to start the low pulse on WRT N you would write a 0b00000001 to make it go low and keep STB_N high. You will need to initialize both DDRD to SFF and DDRB to S03 to designate ports as outputs.

Explanation / Answer

The problem has many parts so I will solve by writting the complete program and providing necessary comments for better understanding.

I have written program in Assembly language for 8085 MIcroprocessor . The main idea is same for all microprocessors and you can write it for other Microprocessors also.

Now Program starts:

Step 1

Go to memory 0000H

Step 2

LXI SP,STACK ;Initialize stack pointer

LXI H,0100H ;Point index where our Hexadecimal content is stored.

LXI D,0101H ;Point index where our ASCII code is to be stored.

MOV A,M ;TRANSFER BYTE

MOV B,A ; SAVE BYTE

RRC

RRC

RRC

RRC

CALL ASCII ;CALL TO CONVERSION SUBROUTINE

STAX D ;STORE THE FIRST ASCII HEX IN 0101H

INX D ;POINT TO NEXT MEMORY LOCATION , GET READY TO STORE NEXT BYTE

MOV A,B ;GET NUMBER AGAIN FOR SECOND DIGIT

CALL ASCII

STAX D

HLT ;HAULT

Now we have used subroutine ASCII we have to write code for it also.

ASCII:THIS SUBROUTINE CONVERTS A HEX DIGIT BETWEEN 0 TO F TO ASCII HEX CODE

INPUT: SINGLE HEX NUMBER BETWEEN 0 TO F

OUTPUT:ASCII HEX CODE IN THE ACCUMULATOR

ANI 0FH ;MASK HIGH ORDER NIBBLE

CPI 0AH ;IS DIGIT LESS THAN (10)10

JC CODE ; IF DIGIT LESSS THAN 1010 THEN GO TO CODE(LABEL USED BELOW)

ADI 07H ;ADD 7H TO OBTAIN CODE FOR DIGITS IN BETWEEN A TO F

CODE: ADI 30H ;ADD BASE NUMBER 30H

OUT PORTD

RET ;RETURN COMMAND

Step 3:

Run program by

G$0000H

**************************************END OF PROGRAM****************************************************************

So, Basic idea behind above program is that two Hexa digits are masked separately and then individual digit ASCII code is generated by calling a subroutine ASCII .

Now in ASCII we have simply used the logic that if digit is less than 1010 then add 30H .

Add 7H if digit is greater than 1010.

Please rate my answer if you like it . If you need any further help I will try to help you in comment section . But this is the best solution to your problem.

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