0

This is what I have got so far. This is 32-bit multiplication is a 32 bit. I would like to improve this code and calculate x^y. I would really appreciate it if you give me a sample code. This code use sub-rutine

ex) 4^3=64

  ORG 10
LA, LDA AH
    SNA //negative skip
    BUN LB // if A >= 0
    CMA
    STA AH
    LDA AL
    CMA
    INC
    STA AL
    CLA
    CIL
    ADD AH
    STA AH
    ISZ C_sign


// if A >= 0
LB, LDA BH
    SNA
    BUN L0 // if B >= 0
    CMA
    STA BH
    LDA BL
    CMA
    INC
    STA BL
    CLA
    CLE
    ADD BH
    STA BH
    ISZ C_sign

L0, CLE
    LDA BH   /  load
    CIR     / 
    STA BH   / 
    LDA BL
    CIR
    STA BL
    SZE     
    BUN L1  / 
    BUN L2  / 

/ if E == 1:
L1, LDA CL2 / 
    ADD AL  / 
    STA CL2 / 
    CLA     / 
    CIL     / 
    ADD CL  / 
    ADD AH  / 
    STA CL  / 
    CLA
    CIL
    ADD CH
    ADD AH2
    STA CH
    CLE     / 

L2, LDA AL  / A  load
    CIL     / A *= 2
    STA AL  / A wo hozon
    LDA AH  / 
    CIL     / AH = 2*AH + E
    STA AH  / 
    LDA AH2
    CIL
    STA AH2
    CLE

    ISZ K   / 
    BUN L0  / 
LC, LDA C_sign
    CIR
    SZE
    BUN C_nega
FIN,CLA
    STA AH2
    STA C_sign
    STA CL2
    HLT

C_nega,LDA CH
    CMA
    STA CH
    LDA CL
    CMA
    INC
    STA CL
    CLA
    CIL
    ADD CH
    STA CH
    BUN FIN

AH2, HEX 0 / high of A
AH, HEX FFFC / int of A
AL, HEX 0 / decimal of A

BH, HEX FFFC / int of B
BL, HEX 0 / decimal of B

C_sign, HEX 0 /if C_sign % 2 == 1, C is negative
CH, HEX 0 / int of A*B
CL, HEX 0 / decimal of A*B
CL2, HEX 0 / decimal of A*B


K,  DEC -32
    END
phuclv
  • 37,963
  • 15
  • 156
  • 475
Jenny I
  • 91
  • 1
  • 2
  • 7
  • 6
    What CPU/iset? What method of computing pow? For stuff like this is better to do it in C/C++ first and then once working port to asm. See [Power by squaring for negative exponents](https://stackoverflow.com/a/30962495/2521214) as you can see there are more methods to use... I assume integer math only so I recommend to start with power by squaring. Its core is multiplication. Also 32 bit* 32bit is 64 bit result ... What are the input and output of your multiplication, where it starts? What are the restrictions? Where exactly are you stuck? – Spektre Jun 14 '20 at 05:59
  • 2
    The asm syntax is weird what it means `/` comments in assembly where usually done by `; bla bla bla` in C/C++ style compatible compilers by `// bla bla bla` but `/ bla bla` ?? how the compiler can differ between division and comment or what the heck that is? What instructions you got it looks similar to Z80 and i8080 but not quite ... Also the labels are separated by `,` ?? havent code in asembly for ages but that syntax just does not look right to me – Spektre Jun 14 '20 at 06:06
  • 2
    What architecture are you programming for? – fuz Jun 14 '20 at 10:24
  • 1
    You should have mentioned that you are using Instruction set of **Basic Processor** defined in **Morris Mano's** book **Computer System Architecture**. – ajit Jun 15 '20 at 05:19

0 Answers0