me and my friend are trying to write a code in which we need to multiply two 32 bit numbers resulting in a 64 bit number. We wanted to multiply the numbers using the add method, the problem is that register can only store 8 bits (16 bits a pair) at a time. We've searched for solutions and it has been hard to find anything really helpful to this situation. Could you give us any hint on how to do this?
(Assembly - 8085) Multiply 32 bit numbers
2.9k views Asked by Gonçalo At
2
There are 2 answers
0
KinJin
On
Let the two numbers be AA55h and BB22h. We will use the 2nd number as a counter. The ALP is:
LXI B, AA55h LXI D, BB22h; counter LXI H, 0000h; 16bit carry initialization
Start: MOV A,C ADD C MOV C,A
MOV A,B ADC B MOV B,A
JNC Carry INX H Carry: DCX D; decrement counter JNZ Start
;;16 bit carry has been stored in HL pair ;;16 bit result has been stored in BC pair
Related Questions in ASSEMBLY
- Is there some way to use printf to print a horizontal list of decrementing hex digits in NASM assembly on Linux
- How to call a C language function from x86 assembly code?
- Binary Bomb Phase 2 - Decoding Assembly
- AVR Assembly Clock Cycle
- Understanding the differences between mov and lea instructions in x86 assembly
- ARM Assembly code is not executing in Vitis IDE
- Which version of ARM does the M1 chip run on?
- Why would %rbp not be equal to the value of %rsp, which is 0x28?
- Move immediate 8-bit value into RSI, RDI, RSP or RBP
- Unable to run get .exe file from assembly NASM
- DOSbox automatically freezes and crashes without any prompt warnings
- Load function written in amd64 assembly into memory and call it
- link.exe unresolved external symbol _mainCRTStartup
- x86 Wrote a boot loader that prints a message to the screen but the characters are completely different to what I expected
- running an imf file using dosbox in parallel to a game
Related Questions in 32-BIT
- PHP php_mongodb.dll for 32bit
- How to handle the "Could Not Load SSL Library" error in Delphi 7 when Posting JSON Data
- I am trying to read an JPEG image, which is of 32 bits pixels, but ImageIO.read(new File(path)).getColorModel() akways returns 24 bits
- How to run a 32bit dotnet 6 console application in Ubantu machine
- "Error while linking" while compiling empty project using Lazarus (fpc) 32bit on debian-based Linux
- Different errors between cl.exe 64-bit and 32-bit
- Using MinGW to compile 32-bit modern applications on Windows
- gcc: error: unrecognized -march target: armv5
- Running a x86 server inside a x64 library using C++ (MSVC)
- Pandas Series with dtype=int defaulting to int32 instead of int64 on 64-bit Python environment
- Why node binary size is way more than pre-build binary while cross compiling to 32 bit ARM
- MacOS Computer Systems: A Programmer's Perspective labs setup
- pwnlib.exception.PwnlibException: kernel architecture must be specified
- Will OpenCV Python - Structural Similarity Index Measure Method have the 32bit Python Support
- Flutter 32-bit Android device - mmap failed errno 12 Out of memory
Related Questions in MULTIPLICATION
- RiscV checking if overflow has occurred during multiplication
- Replace last value in each row of a 2d array with the product of all values in the row excluding the last
- How to access specific elements (by index) in Keras?
- Understanding the Output of Vector and Matrix Multiplication in R
- How many additions operation can be performed instead of single multiplication in FPGA?
- Multiply two columns of different dataframes in Python
- Multiplications a*b vs a*0: execution time
- How to combine elements in Karatsuba multiplication
- Multiplying 2 values gives the original value but dividing the same values gives the right answer
- vectorize numpy array multiplication
- Multiplying Two Tables in R
- Intel xmm registers do not load and multiply correctly
- How does the Radix-2 Montgomery multiplication algorithm R2MM work on bit level?
- How to multiple two values of type driver.Value
- Table multiplication in Angular using ngFor
Related Questions in 8085
- Label "labelname" is not defined
- How can I multiply two one byte hex numbers using rotation in mp8085 (dyna one)?
- How to write clean and efficient Intel 8085 ASM programs?
- MOV r, M instruction in 8085 microprocessor
- How many machine cycles does the HLT instruction require on the intel 8085?
- How do I need to change assembly code that it is going to work correctly?
- How should I change the code using the 8085 microprocessor to execute and read what is in quotes?
- How to put label with 8085 microprocessor in assembly language?
- How can I run assembly code by bypassing the operating system?
- Assembly problem adding unknown value into A
- How were programs written in 8085 assembly dumped into memory
- 'Label' in assembly language - opcode
- Why does CMP L and CMP M instructions in Microprocessor 8085 have same opcode BD?
- Current state of Stack Pointer in 8085
- 8085 microprocessor connection of CPU data bus with RAM data bus
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Addition is addition, we learned addition in grade school.
9+1 = 0 carry the one, we do that twice, then get 0+1 = 1
Doesnt matter what base, in binary we could have this:
same deal, base 2, 1+1 = 0 carry the 1, repeat that until 1+0 = 1
But unlike paper and pencil we have a stronger limit on the number of bits in a computer, but that doesnt in any way change how it works.
I can take the prior problem and divide it into two bit sized registers.
the first one is the low order two bits 11+01 we do the math and get 00 with a carry out of 1. the second operation takes the carry out of the prior operation uses that as a carry in, then we add 01 + 00 with a carry in of 1, and get 10 with a carry out of 0.
Nothing magic there.
Then lets get more fundamental
we start with the lsbit which is 1+1 with a carry in of 0, so 0+1+1 = 0 with a carry out of 1. That carry out is the carry in of the next column the twos column. Which is the carry in of 1 plus 1 + 0 = 0 with a carry out of 1. the fours column is the same as the twos 1 + 1 + 0 = 0 with a carry out of 1. the eights column is a carry in of 1 + 0 + 0 = 1 with a carry out of 0. Every column works the same three things added together the carry in plus operand a plus operand b then you get a result bit and a carry out bit. You can chain those together as wide as you wish, millions of bits, billions of bits, infinite.
So assembly generally gives you some support here. Your alu tends to have a carry out that tends to go into a carry flag bit in some processor state register. You have your two operands and a result, the intermediate carry outs becoming carry ins are managed in the alu itself and you dont get to see those. Sometimes you have a normal add instruction and another add with carry instruction, where the carry flag is the carry in and then the carry out lands in that carry bit as well so for systems like that you would
for as wide of a set of values you want usually limited by the amount of memory you have or other similar limitations (number of registers).
If you dont have an add with carry then you have to synthesize that
Some instruction sets only have an add with carry so
I am obviously leaving the registers/operands off of these instructions as they are not important to the "how do I do math greater than the number of bits I have in a register" type of question. As shown above with the 1 and 2 bit math you need to prepare your data and place it in the operands based on the columns you are working on. If you have 8 bit registers and an 8 bit alu then you divide your N bit operands into 8 bit parts, organize them such that you work on the lower bytes first then the next higher order bytes in the second add and so on. Properly chaining your carry out of one stage into the carry in of the next.
Not sure why there was any problem searching for solutions. Grade school math covers the basics of counting and adding and carrying over to the next column, then you take that to the instruction set documentation where it describes the add and if there add with carry. Showing the add operation modifies the carry bit, and the add with carry uses and modifies the carry bit.