1

I'm very new to assembly in fact I just started learning today and I am trying to figure out a way to change a value stored in .data to something else in the _start: area of the code. I have tried several ways to do this but I can't seem to figure it out. I do get 2 errors:

main.asm:5: warning: character constant too long
main.asm:5: error: invalid combination of opcode and operands

Code:

section .text
    global _start       
_start:                  

    ;where the issue starts
    mov msg, 'Hello, world.' ; i want to change the value to hello world with a . instead of a !
    mov edx, len    ;message length
    mov ecx, msg    ;message to write
    mov ebx, 1      ;stdout
    mov eax, 4      ;system call number (sys_write)
    int 0x80        ;call kernel
    
    mov eax, 1      ;system call number (sys_exit)
    int 0x80        ;call kernel

section .data

msg db  'Hello, world!',0xa ;The original string
len equ $ - msg         ;string length
1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
user15446500
  • 116
  • 5
  • 1
    You can't write to a label. The destination of `mov` must be a memory reference (in brackets `[...]`) or a single register. You also cannot write an entire string, you have to decompose it into manageable chunks. (Traditionally, 1 byte, though you can work with two-byte or four-byte chunks too.) – ecm Oct 15 '21 at 16:47
  • To change one byte in msg, do something like `mov [msg+12], al` – stark Oct 15 '21 at 17:01
  • what if i wanted to change all the bytes – user15446500 Oct 15 '21 at 17:02
  • Then you need `movs` – stark Oct 15 '21 at 17:12
  • how would i go about using movs – user15446500 Oct 15 '21 at 17:16
  • 2
    More generally, to change all the bytes, you write a whole bunch of `mov` instructions, or you write a loop. `rep movsb` is useful if the desired contents are elsewhere in memory and need to be copied without change, see https://stackoverflow.com/questions/27804852/assembly-rep-movs-mechanism/43845229#43845229. – Nate Eldredge Oct 15 '21 at 17:28
  • i'm still very confused – user15446500 Oct 15 '21 at 17:41
  • Strings aren't "first class" objects in asm. They're just arrays of chars. You can't `mov` a whole array, only at most 4 bytes with a single `mov` in 32-bit mode, e.g. a pointer. e.g. you can do `mov word [msg], "xy"` to update the first 2 bytes of the array at `msg:`. – Peter Cordes Oct 15 '21 at 21:37

0 Answers0