2

I have several variables which store the ASCII for a number from a timer, I need to join all the variables into a single string in order to print them on a macro.

Example

mov number_1, 30h
mov number_2,31h
mov number_3,32h

Join them

mov time, number_1
mov time, number_2
mov time, number_3 
Mike
  • 4,041
  • 6
  • 20
  • 37
Jeremy
  • 1,447
  • 20
  • 40
  • 4
    1) You can't move memory to memory like that. You need to use a register as an in-between. 2) Storing all characters at the same address (`time`) would be pointless. You want to use `time`, `time+1`, etc. – Michael Apr 29 '19 at 08:08

1 Answers1

2
mov number_1, 30h
mov number_2,31h
mov number_3,32h

In order to join them you don't have to do anything at all if you defined all of those *number_ * variables consecutively as byte-sized variables. Their storage will be adjacent and thus referring to the 1st number_1 variable will be tantamount to referring to the string. If necessary you can attach a string terminator.

number_1  db ?
number_2  db ?
number_3  db ?
          db 0

If you insist on copying to a separate string, then you could do it like this:

number_1  db ?
number_2  db ?
number_3  db ?
...
time      db 3 dup (?), '$'   ; With $-terminator this time, you choose

...

cld                   ; You need this only once (most of the time)
lea     si, number_1  ; Source
lea     di, time      ; Destination
movsw                 ; number_1 and number_2 together
movsb                 ; number_3

or

mov     ax, number_1  ; number_1 and number_2 together
mov     time, ax      ; number_1 and number_2 together
mov     al, number_3  ; number_3
mov     time+2, al    ; number_3
Sep Roland
  • 33,889
  • 7
  • 43
  • 76