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 6330351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:51:16+00:00 2026-05-24T17:51:16+00:00

Im trying to multiply two 16 bit numbers with the following NASM codes: mov

  • 0

Im trying to multiply two 16 bit numbers with the following NASM codes:

mov ax, [input1]
mov bx, [input2]
mul bx

The result of the previous codes is stored in DX:AX

Im trying to print the integer to the screen using a function from a separate library “print_int”. But print_int requires that the integer must be in the EAX register.

How can i put the 32-bit integer in the EAX register?

Update

I came up with this

mov cx, dx  ;move upper half(16 bits) of result in cx
shl ecx, 16 ;shift the contents of ecx 16 bits to the left
mov cx, ax  ;move lower half(16 bits) of result in cx
  • 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-05-24T17:51:17+00:00Added an answer on May 24, 2026 at 5:51 pm

    Like this:

    ; Before: 
    ; Result is in DX:AX on the form ABCD:EFGH
    ; EAX = ????EFGH : AX contains EFGH, upper part of EAX has unknown content
    ; EDX = ????ABCD : DX contains ABCD (the 16 most siginficant bits 
    ;                                   of the multiplication result) 
    ;                                   like with EAX the upper (=most siginifcant) 
    ;                                   16 bits of EDX also has unknown content.
    
    and eax, 0x0000ffff ; clear upper bits of eax
    ; EAX = 0000EFGH
    
    shl edx, 16 ; shift DX into position (will just shift the upper 16 junk bits away)
    ; EDX = ABCD000
    
    or eax, edx ; combine in eax
    ; EAX = ABCDEFGH
    

    The reason why this works is that ax refers to the 16 least significant bits of eax. Fore more detail see this SO question and the accepted answer. This method will also work for imul, but usually you have to be careful when dealing with signed numbers in assembly code.

    A complete example:

        bits 32
    
        extern printf
        global main
    
        section .text
    main:
        push ebx
        mov ax, 0x1234
        mov bx, 0x10
        mul bx
        and eax, 0x0000ffff ; clear upper bits of eax
        shl edx, 16 ; shift DX into position
        or eax, edx ; and combine
        push eax
        push format
        call printf
        add esp, 8
        mov eax, 0
        pop ebx
        ret
    
        section .data
    format: db "result = %8.8X",10,0
    

    Compile with:

    nasm -f elf32 -g -o test.o test.asm
    gcc -m32 -o test test.o
    

    Update:

    On 32-bit machines it is usually easier and preferable to deal with 32-bit values if it is reasonable in the context. For example:

        movzx eax, word [input1] ; Load 16-bit value and zero-extend into eax
        movzx edx, word [input2] ; Use movsx if you want to work on signed values
        mul eax, edx ; eax *= edx
    

    Which also shows the usage of one of the newer, easier to use, mul instructions. You can also do as you’re doing now and mov ax, [input1] and then later extend the size with movzx eax, ax.

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

Sidebar

Related Questions

I am trying to multiply two 3x3 matrices. The first 2 numbers in the
Am new to this guys need your help! Am trying to multiply two field
I am trying to multiply two strings, but I am getting the wrong answer.
Im trying to write a program which get two 6-digit decimal numbers and show
I'm trying out a very simple program in LAZARUS to multiply two text box
I am trying to multiply a double value by -1 to get the negative
I'm having a bit of trouble trying to delete rows that haven't been loaded
With only a bit of previous experience with databases and no formal education with
I'm trying to create a stored procedure that retrieves data from 3 tables on
I'm trying to get the values from multiple textboxes using JQuery. I'm a bit

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.