Memory Pointers Data Strings

Print   

02 Nov 2017

Disclaimer:
This essay has been written and submitted by students and is not an example of our work. Please click this link to view samples of our professional work witten by our professional essay writers. Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of EssayCompany.

Roll No. 10002034

Lab partner: Shivanshu Arora

Roll No. 10001010

Memory Pointers, Data Strings, and 16-bit Data

Problem 2:

Program Desc ri pti on: The following program continuously counts from 00 to FFH and displays the count ; at the interval of given delay at the LED port. Here we have given a delay of 1 second.So,This program displays seconds on a seven segment LED, using different subroutines like delay1, unpack,

look-up, display, update.

Declarations

COUNT1 .EQU 1428H COUNT2 .EQU 0AH

PORT1 .EQU 00H

PORT2 .EQU 01H BUFF1 .EQU 6120H BUFF2 .EQU 6121H

Main program

ORG 6000H

START:

MVI A, 80H

;Set up the output port

OUT 03H

MVI B, 00H

;Initialize counting to zero

NEXT:

CALL UNPACK

;Unpack the byte

CALL DISPLAY

;Display the byte

CALL DELAY1

;Introduce one second of delay

CALL UPDATE

;Increment count

JMP NEXT

;Continue counting

RST 1

1 | P a g e

Subrout ine 1: Delay 1

Description: This subroutine is introduces to get a time delay of one sec.The affected registers are C, DE.

ORG 6020H

DELAY:

MVI C, COUNT2

;Load delay count for outer loop

LOOP2: LXI D, COUNT1 ;Load delay count for inner loop

LXI D, COUNT1

;Load delay count for inner loop

LOOP1:

DCX D

;Decrement count in DE

MOV A, E

ORA D

;Set Z flag for (D) & (E) = 0

JNZ LOOP1

;If Z =/ 1, repeat loop

NOP

;For additional delay

DCR C

;Decrement count - outer loop

JNZ LOOP2

;If Z =/ 1, repeat the loop

RET

;Return to the ‘main program’

Subrout ine 2: Unp ack

Description: This subroutine unpacks a byte into digits and stores

them in memory locations BUFF1 and BUFF2.The affected registers are C,DE.

ORG 6050H

UNPACK:

MVI C,04H

;Load count for rotating bits in a register four times

MOV A,B

;Load byte to unpacked

ANI 0F0H

;Mask least significant nibble

ROTATE:

RRC

;Rotate bits right without carry

DCR C

;Decrement count

JNZ ROTATE

;If count is not zero, rotate again

STA BUFF1

;Store the most significant nibble in BUFF1

MOV A,B

;Load byte again

ANI 0FH

;Mask most significant nibble

STA BUFF2

;Store least significant nibble in BUFF2

RET

;Return to main program

2 | P a g e

Subroutine 3: Look-up

Description: This subroutine looks for the seven segment LED HEX code stored for numbers 0-9 .The affected registers are A,HL.

ORG 6090H

LOOKUP:

LXI H,6110H

;Set memory pointer for look up table of HEX

code

ADD L

;Get the LSByte of memory location of the

number

MOV L,A

;Set memory pointer for the HEX code of number

MOV A,M

;Load seven segment LED HEX code for the number

RET

;Return to main program

Subrout ine 4: D i SPL aY

Description: This subroutine displays the number on seven segment LED .Any register is

Not affected.

ORG 60B0H

DSPLY:

LDA BUFF1

;Load MSByte

CALL LOOKUP

;Get seven segment LED HEX Code for it

OUT PORT1

;Output at PORT1

LDA BUFF2

;Load LSByte

CALL LOOKUP

;GEt seven segment LED HEX code for it

OUT PORT2

;Ouput at PORT2

RET

;Return to main program

3 | P a g e

Subrout ine 5: Update

Description: This subroutine increments the count by 1 .Here only B register is affected.

ORG 60D0H

UPDATE:

MOV A,B

;Load previous count

INR A

;Increment count

CPI 5AH

;Check if it is equal to 60 (in BCD)

JNZ HERE

;If count is less than 60 (in BCD), continue

MVI A,00H

;If count is 60, reset it to zero

HERE:

ORA A

;Set flags for DAA instruction

DAA

;Convert number into BCD

MOV B,A

;Store count in B

RET

;Return to main program

4 | P a g e

Flow charts:

a) Main program:

Start

Set up output port

Initialize counter to zero

Call unpack subroutine to unpack the digits and store in two memory locations

Call display subroutine to display the digits in memory at output port

Call delay subroutine

Call update subroutine to increment count

5 | P a g e

b) Subroutine 1 (DELAY1) :

Start

Load register C

Load register DE

Decrement

Register DE

No

Is Register DE =

0? No

Yes

Decrement register C

Is register C =

0?

Yes

Return to main program

6 | P a g e

C)Subroutine 2 (UNPACK):

Start

Load byte

Mask LSNibble

Shift left 4 times

Store result

Get the byte again

Mask MSNibble

Store result

Return to main program

c) Subroutine 3 ( LOOKUP)

Start

Set memory pointer for look up table

Get LSByte of memory location of

Hex code

Set memory pointer for Hex code

Load hex code

Return to main program

7 | P a g e

d) Subroutine 4 (DISPLAY):

Start

Load MSbyte

Call LOOKUP to get hex code

Send Hex code to output port

Load LSbyte

Call LOOKUP to get hex code

Send Hex code to output port

Return to main program

e) Subroutine 5 (Update):

Start

Load previous count

Increment count

Is count 60 ?

Yes

No

Reset count

Convert count to BCD

Return to main program

8 | P a g e

Program Assembly list file:

Hex code Mnemonics Comments

COUNT1 .EQU 1428H COUNT2 .EQU 0AH PORT1 .EQU 00H

PORT2 .EQU 01H BUFF1 .EQU 6120H BUFF2 .EQU 6121H

ORG 6000H

3E 80 START: MVI A, 80H ;Set up output port

D3 03 OUT 03H

06 00 MVI B, 00H ;Initialize counting to zero

CD 50 60 NEXT: CALL UNPACK ;Unpack the byte

CD B0 60 CALL DISPLAY ;Display the byte

CD 20 60 CALL DELAY1 ;Introduce 1 sec delay

CD D0 60 CALL UPDATE ;Increment count

C3 06 60 JMP NEXT ;Continue to count

CF RST 1

ORG 6020H

0E 0A DELAY1: MVI C, COUNT2 ;Load delay count for outer loop

11 28 14 LOOP2: LXI D, COUNT1 ;Load delay count for inner loop

1B LOOP1: DCX D ;Decrement count in DE

7B MOV A, E

B2 ORA D ;Set Z flag if (D) & (E) = 0

C2 25 60 JNZ LOOP1 ;If Z =/ 1, repeat the loop

00 NOP ;For additional delay

0D DCR C ;Decrement count -outer loop

9 | P a g e

C2 22 60

C9

0E 04

UNPACK:

JNZ LOOP2

RET

ORG 6050H MVI C,04H

;If Z =/ 1, repeat the loop

;Load count for rotating bits in a register

four times

78

MOV A,B

;Load byte to unpacked

E6 F0

ANI 0F0H

;Mask LSB

0F

ROTATE:

RRC

;Rotate bits right without carry

0D

DCR C

;Decrement count

C2 55 60

JNZ ROTATE

;If count is not zero rotate again

32 20 61

STA BUFF1

;Store the MSB in BUFF1

78

MOV A,B

;Load byte again

E6 0F

ANI 0FH

;Mask MSB

32 21 61

STA BUFF2

;Store LSB in BUFF2

C9

RET

ORG 6090H

21 10 61

LOOKUP:

LXI H,6110H

;Set memory pointer for look up table of

HEX code

85

ADD L

;Get the LSB of memory location of the

number

6F

MOV L,A

;Set memory pointer for the HEX code of

number

7E

MOV A,M

;Load seven segment LED HEX code for the

C9

RET

;Return to main program

ORG 60B0H

3A 20 61

DSPLY: LDA BUFF1

;Load MSByte

CD 90 60

CALL LOOKUP

;Get seven segment LED HEX Code for it

D3 00

OUT PORT1

;Output at PORT1

3A 21 61

LDA BUFF2

;Load LSB

10 | P a g e

CD 90 60

CALL LOOKUP

;Get seven segment LED HEX code for it

D3 01

OUT PORT2

;Ouput at PORT2

C9

RET

ORG 60D0H

78

UPDATE:

MOV A,B

;Load previous count

3C

INR A

;Increment count

FE 5A

CPI 5AH

;Check if it is equal to 60 (in BCD)

C2 D9 60

JNZ FINISH

;If count is less than 60 (in BCD), continue

3E 00

MVI A,00H

;If count is 60, reset it to zero

B7

FINISH:

ORA A

;Set flags for DAA instruction

27

DAA

;Convert number into BCD

47

MOV B,A

;Store count in B

C9

RET

;Return to main program

ORG 6110H

DB 3FH, 06H, 5BH, 4FH, 66H, 6DH, 7DH, 07H, 7FH, 6FH

11 | P a g e



rev

Our Service Portfolio

jb

Want To Place An Order Quickly?

Then shoot us a message on Whatsapp, WeChat or Gmail. We are available 24/7 to assist you.

whatsapp

Do not panic, you are at the right place

jb

Visit Our essay writting help page to get all the details and guidence on availing our assiatance service.

Get 20% Discount, Now
£19 £14/ Per Page
14 days delivery time

Our writting assistance service is undoubtedly one of the most affordable writting assistance services and we have highly qualified professionls to help you with your work. So what are you waiting for, click below to order now.

Get An Instant Quote

ORDER TODAY!

Our experts are ready to assist you, call us to get a free quote or order now to get succeed in your academics writing.

Get a Free Quote Order Now