## LDI variable,' '

11 posts / 0 new
Author
Message

Encontré esta instrucción LDI rmp,'  ' , en la linea de comentario dice "overwrite with blank", esta instrucción esta dentro de una subrutina que detecta un cero(0).

he ejecutado el código y lo que hace es cargar el valor de 0x20 a la variable " rmp =0x20"

, deseo saber porque se hace esta instrucción, esta instrucción se encuentra antes de enviarlo como ASCII a un LCD.

Anexo el código:

Bin2ToAsc5:
rcall Bin2ToBcd5 ; convert binary to BCD
;ldi rmp,4 ; Counter is 4 leading digits
;mov rBin2L,rmp
Bin2ToAsc5a:
ldi r16,0
mov r0,r16

ld rmp,z ; read a BCD digit
tst rmp ; check if leading zero
brne Bin2ToAsc5b ; No, found digit >0
;-------------------------------------------
ldi rmp,' ' ; overwrite with blank
st z+,rmp ; store and set to next position
dec rBin2L ; decrement counter
brne Bin2ToAsc5a ; further leading blanks
ld rmp,z ; Read the last BCD

Bin2ToAsc5b:
rcall Bin2ToBcd5 ; Subrutina convertir de binario a BCD
ldi r25,0x30

-

-

-

This topic has a solution.
Last Edited: Mon. Jun 10, 2019 - 08:12 PM

Please do not cross post or post duplicates!

Also, English is the board language.

Jim

Until Black Lives Matter, we do not have "All Lives Matter"!

Last Edited: Mon. Jun 10, 2019 - 06:41 PM

I found this LDI instruction rmp, '', in the comment line it says "overwrite with blank", this instruction is inside a subroutine that detects a zero (0).

I have executed the code and what it does is load the value of 0x20 to the variable "rmp = 0x20"

, I want to know why this instruction is done, this instruction is found before sending it as ASCII to an LCD.

Attach the code:

Bin2ToAsc5:
rcall Bin2ToBcd5 ; convert binary to BCD
;ldi rmp,4 ; Counter is 4 leading digits
;mov rBin2L,rmp
Bin2ToAsc5a:
ldi r16,0
mov r0,r16

ld rmp,z ; read a BCD digit
tst rmp ; check if leading zero
brne Bin2ToAsc5b ; No, found digit >0
;-------------------------------------------
ldi rmp,' ' ; overwrite with blank
st z+,rmp ; store and set to next position
dec rBin2L ; decrement counter
brne Bin2ToAsc5a ; further leading blanks
ld rmp,z ; Read the last BCD

Bin2ToAsc5b:
rcall Bin2ToBcd5 ; Subrutina convertir de binario a BCD
ldi r25,0x30

-

-

-

This reply has been marked as the solution.

rmp is a 'name' given to 'something....in this case it's most likely a register

The hex value 0x20 in ASCII is the SPACE character, so by putting a SPACE between to apostrophe's its the same as writing

`ldi rmp,0x20 ; overwrite with blank`

Why they elected to call it a 'blank' is something I cannot explain

Est coast Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

ldi instruction loads a constant (value) into the specified register (only register numbers r0 to r15 allowed).   "blank" character is often used as a poor wording choice for "space" character, which is 0x20, or \$20.

somewhere rmp has been defined as the name of some register (r0 to r15)

like:

.def rmp=r12    ;rmp is now same as typing r12

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

avrcandies wrote:
ldi instruction loads a constant (value) into the specified register (only register numbers r0 to r15 allowed)

You sure?

I have been using R16 as my 'working' register and perform the LDI instruction to it, and any other register.

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

When writing to an LCD, it's pretty common to write the full width of the display, and you want to pad the part that doesn't contain your values with spaces.

first it's r16 to r31 you can use LDI on.

I have only looked shortly at it but it looks like it's so they get "   345" instead of "00345"

sparrow2 wrote:
first it's r16 to r31 you can use LDI on.

Correct.  I looked it up after I hit post and realised my answer was rather vague.

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

"The critical shortage here is not stuff, but time." - Johan Ekdahl

"Step N is required before you can do step N+1!" - ka7ehk

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user