Translate the following C program into NASM.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter3: Assignment, Formatting, And Interactive Input
Section3.3: Using Mathematical Library Functions
Problem 3E: (Practice) Write C++ statements for the following: a.b=sinxcosxb.b=sin2xcos2xc.area=( cbsina)/2d.c=...
icon
Related questions
Question
100%

(NASM) This is a lab about indexing an array and a string (C string with a null character at the end).

 

  1. Translate the following C program into NASM.

int ary[] = {12, 40, -2, 89, 35, -7, 6};

int main()

{

     int sum = 0;

     int highest = 0;

     for (int x = 0; x < 7; x++) {

         if (highest < ary[x])

              highest = ary[x];

         sum += ary[x];

     }

     printf("Sum is %d\n", sum);

     printf("Highest value is %d\n", highest);

}

Use indexing (the [ebx+esi] or [ebx+edi] form). You can have several “dw” values on the same line. Use the “loop” command.

 

  1. Translate the following C program into NASM.

int main()

{

    int x = 0;

    char sent[20];

    printf("Enter sentence: ");

    scanf("%[^\n]s", sent);

    while (sent [x] != '\0'){

        if (sent[x] >= 'a' && sent[x] <= 'z')

            sent[x] = sent[x] & 0xDF;

        x++;

    }

    printf("%s \n", str);

}

Use indexing (the [ebx] form). You can use the following pseudocode in the “bss” to allocate the array:

    slen equ 20

    sent resb slen

 

Note: the scanf format string of “%[^\n]s” keeps reading characters until the newline (otherwise it would end at the first space).

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning