Ryan N.
Ryan N.

Reputation: 11

How to change the value of a variable in assembly

I am working on some code for my port of MikeOS. It is written in NASM x86 16 bit assembly. I am trying to change a variable that I made to have a different value. It compiles with no errors, but when I call os_print_string, it prints some wierd ASCII characters. Here is the code:

    BITS 16
    ORG 32768
    %INCLUDE "mikedev.inc"



start:
    mov si, test2          ; give si test 2 value
    mov [test1], si        ; give test 1 si's value
    mov si, test1          ;now give test1's value to si
    call os_print_string   ; and print

test2 db "adsfasdfasdf", 0
test1 db "asdf", 0

This code is redundant, I know. I just need a n explanation on how to change a variable's value. Thaks in advance!

-Ryan

Upvotes: 1

Views: 9884

Answers (1)

RAVN Mateus
RAVN Mateus

Reputation: 594

Another good old question, here is the answer you waited for 6.83 years :)

BITS 16
ORG 32768
%INCLUDE "mikedev.inc"

start:
mov si, test2
mov di, test1

.loop:
lodsb
or al, al
je .done
stosb
jmp .loop

.done:
mov si, test1
call os_print_string

test2 db "adsfasdfasdf", 0
test1 db "asdf        ", 0

Make sure the char arrays have the same length or this will break ^^ But i am sure you know that by now ^^

Upvotes: 2

Related Questions