StrNCpyAsm, Assembly Language

;StrNCpyAsm - copy zero terminated string2 to zero terminated string1,
; but copy no more than count (parameter) characters
; or the length of string2, whichever comes first
; entry: - addStr1 contains the address of string1
; - addStr2 contains the address of string2
; - count contains the max number of characters to copy
; exit: NONE (no return value so do not use edi to return an address)
; Note: StrNCpyAsm does not zero terminate the copied string
; unless the 0 is within count characters copied.
; example1: char str1[]= {''h'',''e'',''l'',''l'',''o'','' '',''w'',''o'',''r'',''l'',''d'',0};
; char str2[]= {''G'',''o'',''o'',''d'',''-'',''b'',''y'',''e'',0};
; StrNCpyAsm(str1,str2,4);//terminating 0 not copied since only 4 characters copied
; ;//and terminating 0 not within the 4 characters
; after copy str1 contains: ''G'',''o'',''o'',''d'',''o'','' '',''w'',''o'',''r'',''l'',''d'',0
; example2: use str1 and str2 from example1
; StrNCpyAsm(str1,str2,9); //terminating 0 copied since terminating 0
; //within 9 characters copied
; str1 contains: ''G'',''o'',''o'',''d'',''-'',''b'',''y'',''e'',0,''l'',''d'',0
; example3: use str1 and str2 from example1
; StrNCpyAsm(str1,str2,20);//copy 20 characters upto and including 0,
; //whichever comes first
; //only 9 characters including 0 copied
; after copy str1 contains: ''G'',''o'',''o'',''d'',''-'',''b'',''y'',''e'',0,''l'',''d'',0
; The above is how you would call StrNCpyAsm from C++.
; To call StrNCpyAsm from an asm function use:
; push 20 ;max num of characters to copy
; push str2Add ;address of string 2
; push str1Add ;address of string 1
; call StrNCpyAsm
; ;no add esp, 12 needed because stack cleaup automatically done
;Do not use a loop in this function.
;Choose 2 instructions from the following string instructions to use:
; rep, repe, repne, movsb,stosb,cmpsb,scasb
; hint1: use StrLenAsm to get the number of characters in str2
; hint2: the length returned by StrLenAsm does not include terminating 0
; hint3: copy the lesser of the length of the string (including terminating 0)
; or count characters
;copy to ecx the lesser of count or the length of string2 (including terminating 0)
; Please note for the above, you need the length of string2 including terminating 0.
; StrLenAsm returns the length not including terminating 0
;populate esi and edi with the correct values
;clear the direction flag
;use rep and movsb to copy

StrNCpyAsm PROC uses eax esi edi ecx , ;save registers used
addStr1:DWORD, ;address of string1
addStr2:DWORD, ;address of string2
count:DWORD ;max chars to copy
Posted Date: 12/6/2012 11:39:50 PM | Location : United States

Related Discussions:- StrNCpyAsm, Assignment Help, Ask Question on StrNCpyAsm, Get Answer, Expert's Help, StrNCpyAsm Discussions

Write discussion on StrNCpyAsm
Your posts are moderated
Related Questions
1) Write an 80x86 assembly language program in EXE file format to do the following tasks: a) Open and read the contents of a file into memory (use at least 1 kB). b) Sort the li

Data copy/transfer Instructions MOV: This data transfer instruction transfers data from one register or memory location to another register or memory location. The source can

You have to write a subroutine (assembly language code using NASM) for the following equation.

Description Write a MIPS program that reads a string from user input, reverse each word (defined as a sequence of English alphabetic letters or numeric digits without any punctu

The 486 Introduced in the year 1989 the 80486 did not feature any radically new processor technology. Instead, it joints a 386 processor, a cache memory controller and a math c

Write a MIPS/SPIM assembly language program that prints the smallest and largest values found in a non-empty table of N word-sized integers. The address of the first entry in your

CBW: Convert Signed Byte to Word: This instruction converts a signed byte to a signed word. In other terms, it copies the sign bit of a byte to be converted to all of the bits in

INT N : Interrupt Type N:- In the interrupt structure of 8086/8088, 256 interrupts are distinct equivalent to the types from OOH to FFH. When an instruction INT N is executed,

AAD: ASCII Adjust for Division though the names of these 2 instructions (AAM and AAD) seem to be same, there is many difference between their functions. The AAD instruction conver

As an instance of the normal priority mode, imagine that initially AEOI is equal to 0 and all the ISR and IMR bits are clear. Also consider that, as shown in given figure, requests