Translate the following high level language code into general assembly language:

sum = 0;

for (i = 0; i <= 6; i = i + 2)

{

    sum = sum + i;

}

Assume that sum is located at memory location 100 and that register R0 has the number zero within it.


Answer:

.Ltext0:

.globl main

main:

.LFB0:

.cfi_startproc

0000 55 pushq %rbp

.cfi_def_cfa_offset 16

.cfi_offset 6, -16

0001 4889E5 movq %rsp, %rbp

.cfi_def_cfa_register 6

0004 C745F800 movl $0, -8(%rbp)

000000

000b C745FC00 movl $0, -4(%rbp)

000000

0012 EB0A jmp .L2

.L3:

001a 8345FC02 addl $2, -4(%rbp)

0014 8B45FC movl -4(%rbp), %eax

0017 0145F8 addl %eax, -8(%rbp)

.L2:

001e 837DFC06 cmpl $6, -4(%rbp)

0022 7EF0 jle .L3

0024 5D popq %rbp

.cfi_def_cfa 7, 8

0025 C3 ret

.cfi_endproc

.LFE0:

.Letext0:

Computer Science & Information Technology

You might also like to view...

Describe how to perform a simple search for Ski-Doo recreation vehicles using a search engine.

What will be an ideal response?

Computer Science & Information Technology

Which of the following is not an attribute of the HR element?

(a) SIZE (b) SRC (c) ALIGN (d) NOSHADE

Computer Science & Information Technology

In cloud computing, the user's device or devices connect to the cloud client and saves changes to the documents on that device

Indicate whether the statement is true or false

Computer Science & Information Technology

The first step in adding subtotals to a group or list is to sort the data by the ________ for which you want to create a subtotal

A) block B) list C) query D) field

Computer Science & Information Technology