assembly - I am trying to copy the data of one array to another array -
the codes below attempt copy contents 1 array another. reason not working. can me this?
;copy frequency array calculation array lea dx,frequency lea ax,array mov cx,512 address: mov bx, dx mov ax, bx inc dx inc ax loop address
this code fixed, explanation comes after :
;copy frequency array calculation array lea si, frequency ;si = pointer frequency. lea di, array ;di = pointer array. mov cx, 512 ;counter. address: mov ax, [ si ] ;get 2 bytes frequency. mov [ di ], ax ;put 2 bytes array. add si, 2 ;next 2 bytes in frequency. add di, 2 ;next 2 bytes in array. sub cx, 2 ;counter-2. jnz address ;if ( counter != 0 ) repeat.
dx changed si , ax di because dx , ax cannot used pointers, not allowed [ ax ] or [ dx ]. si , di pointers nature, names mean "source index" , "destination index", can used [ si ] , [ di ]. it's extremely important learn difference between si , [si] : first 1 address, second content of address.
si, di , cx incremented/decremented 2 because not moving bytes words (two bytes). it's faster way.
finally, it's better avoid using words "address" because might reserved words.
Comments
Post a Comment