Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8911055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:50:44+00:00 2026-06-15T03:50:44+00:00

I am trying to write assembly language code for the formula in the comment.

  • 0

I am trying to write assembly language code for the formula in the comment. I am having trouble because the pointers to the arrays are 64 bit registers, and I am supposed to store the final result in a 32 bit register, so I am obviously missing some fundamental understanding of how registers work. I included my attempted solution, but I get errors when I try to use a movl or subl where one argument is a 64 bit register and the other is 32 bits. I’m also not certain if my reasoning is even correct. Any help would be appreciated.

#    WRITEME: At this point, %r12 and %rbx are each pointers to two arrays
#   of 3 ints apiece, a0 and a1.  Your job is to write assembly language code
#   in the space below that evaluates the following expression, putting the
#   result in register %esi (the 32 bit form of register %rsi):
#   
#    (a1[0]-a0[0]) * (a1[0]-a0[0]) + 
#    (a1[1]-a0[1]) * (a1[1]-a0[1]) + 
#    (a1[2]-a0[2]) * (a1[2]-a0[2])
#   
#    
#   It is possible to do this using 11 instructions. You need to use extra
#   registers, of course. Since  you are not calling any functions, you have a
#   lot of choices. %r12 and %rbx are already occupied, but you could use
#   %r13d through %r15d (32 bit forms of %r13 through r15) safely, and also
#   %eax, %ecx, %edx and of course %esi, since that is where the result will
#   be stored.

###########

# Your code here
movl $0, %esi
movl %rbx, %eax #errors here
subl %r12, %eax #and here
imull %eax, %eax
movl 4(%rbx), %ecx
subl 4(%r12), %ecx
imull %ecx, %ecx
movl 8(%rbx), %edx
subl 8(%r12), %edx
imull %edx, %edx
movl %eax, %esi
addl %ecx, %esi
addl %edx, %esi
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:50:45+00:00Added an answer on June 15, 2026 at 3:50 am

    movl %rbx, %eax means: ‘copy the contents of rbx into eax’, however since rbx is a 64-bit register, while eax is a 32-bit register this will fail. I think what you mean to do is ‘copy the contents of memory pointed to by rbx into eax’: movl rbx %eax

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a function in assembly (but lets assume language agnostic for
I am learning AT&T x86 assembly language. I am trying to write an assembly
Hi I'm trying to write some assembly code that uses printf to print a
I'm trying to write an assembly code version of Fibonacci which gives the nth
I'm trying to write in assembly language a function sort. It will sort the
I'm trying to write a code that allows a user to load an assembly
I'm trying to write a re-usable .NET Assembly that implements WCF. My current problem
I m trying write code that after reset set up rrpmax as 3000. It
all, I was trying to write a rot13 with inline assembly function... the following
So I'm trying to write an assembly program that displays the hex address of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.