0

if i have two labels, one being in a .asciiz directive labelled "source". for my program i need to have another .space directive labelled "output" that has to be bigger than the 40 character string, would i just do 41 to represent an extra byte so i can store it in that array? dumb question i know but just wanting to make sure. this is what i had in mind:

source: .asciiz "this is supposed to be 40 characters long!\n"
output: .space 41
yessir
  • 1
  • 2
  • Each character in the `.asciiz` is 1 byte, and it also includes a 0 byte at the end. So if you want to copy that as well to make a valid C string, then yes you need to reserve at least 41 bytes. – Peter Cordes May 11 '22 at 18:46
  • 1
    Your source string as posted occupies 44 bytes, including the newline character and the nul terminator. (copied to excel and had it count) So, if all you're doing is copying that specific string, you'll need 44 bytes of space. If you don't reserve enough space, then whatever comes after (address-wise in the data) will be overwritten. If your `output` is the last item of data with nothing following, such overwrite may be harmless, depending on the environment and length of overrun. – Erik Eidt May 11 '22 at 19:08
  • In a good assembler (not MARS), you could use `output: .space . - source` to reserve the same amount of space as the distance between output and source. i.e. have the assembler calculate the distance in bytes for you. But I don't know of a way to have MARS do that. – Peter Cordes May 11 '22 at 19:28

0 Answers0