Assembly - Multiplication by a constant

Last update on September 26, 2009 10:43 AM by jak58
Published by jak58

Assembly - Multiplication by a constant





Short intro


Assembly languages are set of low-level languages for programming computers and were first developed in the 1950s and are mostly known as second generation programming languages. Important feature of Assembly language, are that, it eliminated much of the error-prone and time-consuming operations required in first-generation programming used in older PC (Tedious operation, such as remembering numeric codes and calculating addresses, became obsolete).

Multiplication under assembly


In assembly you can make a multiplication using the instructions mul (unsigned numbers) and Imul.
It is used as follows:

mul name_registry



The processor increases the content of eax or ax or al (depending on the size of the registry: given in parameter) and then stores the result in eax or ax for the "low" part and the result edx dx or for the "mopart st significant" of the result if the past record of multiple parameter is greater than one byte.

Using mul is a quite troublesome because you will have to move the multiplied value in eax, the value to multiply in a different registry and the registy holding the result must be eax,(overwrites the value it had).

However, if you just want to multiply a registry by a constant and put the result in the registry of your choice, you can use a shortcut with the instruction "lea" (load effective address). This instruction is used to retrieve the address of a data in memory.

lea destination_registry, [memory_address]; place memory_address in destination_registry



The big advantage is that, instead of using the memory address, you can substitution the multiplication or addition of a registry by a constant.

Imagine that you want to multiply by 7 ecx and save the result in ebx, the command would be:
lea ebx, [ecx * 7]



Note that: you can not multiply two registries together using this shortcut.
Best answers for « Assembly Multiplication by a constant » in :
Compiling an assembly program with Nasm Show Compiling an assembly program with Nasm Intro With LInux With Windows Intro Netwide Assembler (NASM) is an assembler and disassembler for the Intel x86 architecture and is commonly used to create 16-bit, 32-bit (IA-32) and 64-bit...
PC Assembly Show Computer Assembly A PC computer is a modular type of computer, it can be assembled using hardware components made by different manufacturers, so as to have a custom built computer according to one's specific needs. The following components are...
Assembling multiple PDF files Show Assembling multiple PDF files Intro Steps: Intro PDF creator is a software allowing you to print several files into one with its printer function. Download link http://en.kioskea.net/telecharger/telecharger-40-pdf...
X86 assembly occurrence of a character Showx86 assembly occurrence of a character Introduction Issue Solution Explanation Introduction The small assembly exercise below is for (Intel and AMD 32-bit) x86 architectures and uses the NASM syntax , an assembler, available...
Useful Links for Assembly X86 ShowUseful Links for Assembly X86 Tutorial Complete manuals Assembly under Windows Assembly under Linux Softwares Emulators Here below you will get some useful links, helping you to cope with assembly X86( for beginners or advanced...
Script to assemble 2 photos ShowScript to assemble 2 photos Issue The code Software requirements Source Issue You ask how to assemble 2 pictures? Sure we can use Gimp , but it is a time consuming process. For those who prefer to work with command lines here's a...
Download Buddy Icon Constructor ShowThe available icons on mention web and foundation of database prefabricated icons are numerous, but this shining in general. Icon Constructor is a tool allowing the conversion of pictures of any format in icons of office. You can use all pictures...
Download Windows XP SP2 ShowWindows XP SP2 Pack services constitute a practical means, everything in one, to reach the last drivers, the tools and the improvement in security as well as the other critical updates. Windows XP SP2 (Pack 2 service), the last Pack service for...
PC Assembly - Hard drive installation ShowHard drives, CD-ROM, DVD-ROM drives and floppy drive The motherboard usually has two IDE (Integrated Device Electronics) connectors: The first connector is known as the primary device controller; The second is known as the secondary device...
PC assembly - Inserting expansion cards ShowInserting expansion cards Expansion cards are plugged into expansion slots. There are several types of slots: ISA slots run at 16 bits. Few computers still use this type of slot as the bus runs at a relatively slow speed. PCI slots run at 32...
PC assembly - Installing the motherboard ShowThe motherboard The motherboard is screwed into the casing. Small risers, called spacers or mounting screws, come with the motherboard and are used to keep a space between the motherboard and the case. These risers are plastic points which "clip"...