2

this is a code for copying 2 strings

TITLE Copying a String (CopyStr.asm)
INCLUDE Irvine32.inc
.data
source BYTE "This is the source string",0
target BYTE SIZEOF source DUP(0)
.code
main PROC
mov esi,0 ; index register
mov ecx,SIZEOF source ; loop counter
L1:
mov al,source[esi] ; get a character from source
mov target[esi],al ; store it in the target
inc esi ; move to next character
loop L1 ; repeat for entire string
exit
main ENDP
END main

mov esi,0 ; index register

why it assumes that the index will start with 0 how did it know that the index of the SOURCE is 0 i think it should be

mov esi , offset Source

???

rkhb
  • 14,159
  • 7
  • 32
  • 60
Osama Al-far
  • 427
  • 3
  • 10
  • 24

2 Answers2

1

Have a look at

mov al,source[esi] ; get a character from source

esi is the "Extended Source Index" register, which stores the offset in the source (string) (more about the ESI/EDI registers here).

Community
  • 1
  • 1
Alexander Pavlov
  • 31,598
  • 5
  • 67
  • 93
0

source is in the .data section, this symbol is the starting address of the string. The esi register stores a byte offset starting at the source address. The lower part of the eax register receives the content of the memory at source base address plus the offset inside esi (0, 1, 2, 3, ... as the loop goes).

Benny
  • 4,095
  • 1
  • 26
  • 27