1. Implement the memset function using inline assembly. The memset function copies “value” starting at the destination address and ending at destination address + nCount – 1. It is used to set a block of memory to a specific value, often times initializing a memory block with a value of zero.

memset( void *destination, unsigned char value, int nCount). Example: dst = 0x1000, value = 0xA5, nCount = 5
Memory values
Before: 0x1000: 3A 28 A1 BE CA FE DE AD 11 ... After:0x1000: A5A5A5A5A5FEDEAD11...

   Note: the last address to get the “A5” value is 0x1004 which is dst
   (0x1000) + nCount (5) – 1.
Void function() {
   char string[] = “The end is near!”;
   printf(“The message is: %s\n”, string);
// this is 16 bytes + null
__asm {
   mov eax,16
   push eax
   mov eax,0x41
   push eax
   lea eax,string
   push eax
; push the length
; push the value
; push the address of string
       call inline_memset
       add esp,12
       jmp EXIT
          ; this is where you write the code to implement the memset
    printf(“Now the message is: %s\n”, string);
   } // end function

1. Implement the memcmp function using inline assembly. The memcmp function compares two byte sequences starting at each source address and ending at each source address + nCount – 1. If they are equal, it returns zero. If source1 has a value less than source2, then it returns -1. If source1 has a value greater than source2, it returns +1.
memcmp( void *source1, void *source2, int nCount)

char source1[] = { 0x05, 0x6F, 0xAA }
char source2A[] = { 0x05, 0x5F, 0xAA } --- return +1 char source2B[] = { 0x05, 0x70, 0xAA } --- return -1

Consider the data as UNSIGNED, i.e. 0xFF > 0x01. Int inline_memcmp(char *s1, char *s2, int length) {
    int resulti;
               ; your code here
    return resulti;
   void function() {
    int tmpi;
    char data[] = { 0x00, 0xF2, 0xAB, 0x16, 0x81, 0x53 };
    char dataA[] = { 0x00, 0xF2, 0xAB, 0x16, 0x81, 0x53 };
    char dataB[] = { 0x00, 0xF2, 0xAB, 0x16, 0x81, 0x53 };
    char dataC[] = { 0x00, 0xF2, 0xAB, 0x16, 0x81, 0x53 };
    tmpi = inline_memcmp(data, dataA, 6);
    printf(Result of dataA is: “, tmpi);
    tmpi = inline_memcmp(data, dataB, 6);
    printf(Result of dataB is: “, tmpi);
    tmpi = inline_memcmp(data, dataC, 6);
    printf(Result of dataC is: “, tmpi);
   } // end function

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>

void function()
char string[] = "The end is near!"; // this is 16 bytes + null
printf("The message is : %s\n", string);
__asm {
mov eax, 16; push the length
push eax
mov eax, 0x41; push the value
push eax
lea eax, string; push the address of string
push eax
call inline_memset
add esp, 12
jmp EXIT

inline_memset :
; this is where you write the code to implement the memset
push ebp; save ebp
mov ebp, esp; copy SP reference

; save registers that will be used
push ebx
push ecx
push edi

; get arguments to registers
mov edi, [ebp + 8]; pointer to start location
mov ebx, [ebp + 12]; value
mov ecx, [ebp + 16]; length

; loop length times
mov[edi], bl; write the value
inc edi; increment pointer
loop L1...

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Assembly Language Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats