bit manipulation - How do I perform bitwise multiplication/division in MASM x86 assembly? -
I have succeeded in writing an MASM x86 assembly program which reverses / divides 16 bit numbers by bit transfer. What I've done so far:
includes Irvine32.inc. Data count byte -1 val1 sdword? Val2 SDWORD? Str1 BYTE "Enter 1 integer here:", 0; Str2 BYTE "Enter integer 2 here:", 0 str3 byte "product is:", 0 mall word? Mval2 WORD? Powered Word? Main PROC mov dh clrscr .code call, 10 mov dl, 20 call gotoxy mov EDX, OFFSET str1 call writeString call ReadInt mov mval, ax mov dh, 12 mov dl, 20 call gotoxy mov EDX, OFFSET str2 call writeString call readInt mov mval2 , Ax mov mov, 14 mov dl, 20 call gotoxy mov EDX, OFFSET str3 call WriteString mov ax, pval call writeInt call CRLF call waitmsg mov eax, 0 mov ax, mval2 mov ECX, 16L1: SHR bx, 1 counting count JNC How do I correctly implement binary multiply? / division?
You are at a point where you should work with the procedures to keep track of the code. Take a look at this 32-bit example and change it to 16-bit:
IrwinName.com. Second DWORD? Results DWORD? GetFirst BYTE "Number 1:", 0 GetSecond BYTE "Number 2:", Linefeed BYTE 13, 10, 0 Minnesin BYTE "*", 0 DivSign BYTE "/", 0 EquSign BYTE "=", 0 Code main PROC MOV EDX, OFFSET GetFirst Call WriteString Phone ReadDec mov first, eax mov EDX, OFSSET GetSecond call WriteString phone ReadDec MOV second, eax mov EBX, first MOV eax, second call BitwiseMultiply mov result, eax mov eax, first call WriteDec MOV EDX, OFFSET MulSign Call WriteString MOV EAX, Second Call WriteDec MOV EDX, OFFSET EquAign Call WriteString MOV EAX, Phone WriteDec MOV EDX Result, OFFSET Linefeed Call WriteString MOV EAX, First MOV EBX, Second Call BitwiseDivide MOV Result, eX MOV Eax, first call WriteDec mov adx, offset, distance call, type straping mop ex, second call right xeve Yes, ADX, offset Ikssain call Likenstres mop EX, results call Raitdek MUD ADX, offset linefeed call Liststring exit Maine Iandeepi; Multiply EBX by EAX Bitwise Multiply uses Proxy EBX ECX EDX mov edx, eax; EDX: Multiplier (EBX: Multiplier) XXEx, EX; The result will be in EX - clear BSR NCX, ADX; ECX = The most important bit of JSR1; Return with EX = 0 if EDX == 0 L1: SRADX, 1; See the correct bit of multiplier jnc @f; Also exclude if this bit == 0x, ebx add; Add multipiland to the result @@: SL EBX, 1; Increase multipline for sub-axis for next round, 1; Reduce the loop variable jnc L1; Loop if ECX> = 0 R1: Rate; Results increase in E.X. breadth ENDP; ECX EDX ESI mov esi, eax; EX by using Exx Beatwise Device Proxy; ESI: Dividend (EBX: Separator) XXEx, Ex; Result (quotient) = 0 xand adx, adx; EDX = 0 (start value) mov cl, 32; 32 loops L1: Shell ASI, 1; Beta 31 from EX ... RCL ADX, 1; ... ADX CMP EBX's Bit1, ADX; Carry, if edex & gt; Divisor and @ f; Leave on deduction == 0 and zero == 0 (result zero) sub-ADX, EBX; Subtract ... STC; ... and take it @@: RCLX, 1; Participating (0 or 1) subcl, 1 GNS L1 for quotient; Loop while CL & gt; 0 rate; Results in E.X. BitwiseDivide ENDP END Main
Comments
Post a Comment