I need to code 32 bit Montgomery modular multiplier (MMM) inMIPS assembly.the MMM algorithm is :s(0) = 0for i = 0 to N-1 q(i) = ( s(i) + a(i) x b ) mod 2 s(i+1) = ( s(i) + q(i) x n + a(i) x b ) / 2if ( s(N) ≥ n ) d = s(N) – nelse d = s(N)MMM( a , b , n ) = d
I need to use the example on 32-bit multiplier assemblycode(code below) as a starting point:
# MIPS assembly code for 32 x 32 unsigned mutliplication.# No subroutines are used. Registers are mapped as follows:# A (multiplier) = $t0, B (multiplicand) = $t1,# H (result-high) = $t2, L (result-low) =$t3,# C (loop-counter) = $t4, T1 (tmp1) = $t5, T2 (tmp2) =$t6# Only the following instructions are used:# ori, sll, srl, addu, subu, sltu, beq# .data .textmain: ori $t0, $0 , 0x1234 # A = 0x00001234 sll $t0, $t0, 16 # A =0x12340000 ori $t0, $t0, 0x5678 # A = 0x12345678;multiplier ori $t1, $0 , 0x8765 # B = 0x00008765 sll $t1, $t1, 16 # B =0x87650000 ori $t1, $t1, 0x4321 # B = 0x87654321;multiplicand ori $t2, $0 , 0 # H = 0; resulthigh word ori $t3, $0 , 0 # L = 0; resultlow word ori $t4, $0 , 32 # C = 32; loopcounterloop: sll $t5, $t0, 31 # T1 =LSB(A)*2^31 srl $t0, $t0, 1 # A = A >>1 beq $t5, $0 , skip # skip addition ifLSB(A)=0 addu $t2, $t2, $t1 # H = H + B sltu $t5, $t2, $t1 # if (OVF) T1 =1skip: sll $t5, $t5, 31 # T1 =T1*2^31 sll $t6, $t2, 31 # T2 =LSB(H)*2^31 srl $t2, $t2, 1 # H = H /2 addu $t2, $t2, $t5 # H = H + T1 srl $t3, $t3, 1 # L = L /2 addu $t3, $t3, $t6 # L = L + T2 ori $t5, $0 , 1 # T1 = 1 subu $t4, $t4, $t5 # C = C - 1 beq $t4, $0 , done # if (C=0) done beq $0 , $0 , loop # else gotoloopdone: jr $ra
I need to code 32 bit Montgomery modular multiplier (MMM) in MIPS assembly. the MMM algorithm is : s(0) = 0 for i = 0 to
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am