Can we use Two 32 bit reg(32 + 32 = 64) at a time

2020-05-03 16:31发布

问题:

Assembly Language 8086:

I have make the program for addition it takes two values in console and gives us result.. it can only take value under 32 bits(8 digits) if we give higher value then it will give error of integer overflow in console

If i want to give more then 32bit value in input1 and input2 how will i do it?

I Want add value1 to value2 by using 32bit register and give value under 64bit(equals to 16 digits).. it is Possible to use the space of 2 reg (32+32 = 64bit)?...

How we can make 2 register of 32 bit to make it 64bit i know it is possible but i don't know how to do it...because i am new in Assembly language

I am using KIP.R.IRVINE Link Libraries in Assembly Language

how we will give 64bit value by using 2 32bit reg? or how we will enable 2 32bit reg to take 64bit value?

here is the code for 32-bit addition:

INCLUDE Irvine32.inc

.data

 Addition BYTE "A: Add two Integer Numbers", 0

 inputValue1st BYTE "Input the 1st integer = ",0
 inputValue2nd BYTE "Input the 2nd integer = ",0

  outputSumMsg BYTE "The sum of the two integers is = ",0

   num1 DD ?
   num2 DD ?
   sum  DD ?

   .code

   main PROC

   ;----Displays addition Text-----

  mov edx, OFFSET Addition
  call WriteString
  call Crlf
  ;-------------------------------

  ; calling procedures here

   call InputValues
   call addValue
   call outputValue

   call Crlf

   jmp exitLabel


   main ENDP


      ; the PROCEDURES which i have made is here


  InputValues PROC
  ;----------- For 1st Value--------


   call Crlf
   mov edx,OFFSET inputValue1st ; input text1
   call WriteString

   ; here it is taking 1st value
   call ReadInt    ; read integer
   mov num1, eax   ; store the value




     ;-----------For 2nd Value----------



      mov edx,OFFSET inputValue2nd ; input text2
      call WriteString


      ; here it is taking 2nd value
      call ReadInt    ; read integer
      mov num2, eax   ; store the value

      ret
      InputValues ENDP




     ;---------Adding Sum----------------

     addValue PROC
     ; compute the sum

     mov eax, num2  ; moves num2 to eax
     add eax, num1  ; adds num2 to num1
     mov sum, eax   ; the val is stored in eax

     ret
     addValue ENDP

     ;--------For Sum Output Result----------

     outputValue PROC

     ; output result

     mov edx, OFFSET outputSumMsg ; Output text
     call WriteString


     mov eax, sum
     call WriteInt ; prints the value in eax


     ret
     outputValue ENDP


     exitLabel:
     exit


    END main

回答1:

You can use ADC in conjunction with ADD to do add something to a 64-bit integer stored in 2 32-bit registers.

You can use SHLD in conjunction with SHL to shift left a 64-bit integer stored in 2 32-bit registers.

If you can do 64-bit addition and 64-bit shifting, you can easily do multiplication of a 64-bit integer by 10 (hint: 10=8+2, x*10=x*8+x*2).

You'll likely need it in order to read 64-bit integers from the console. You'll need to read them as ASCII strings and then convert into 64-bit integers using repeated multiplication by 10 and addition (hint: 1234 = (((0+1)*10+2)*10+3)*10+4).

The above should be enough info to read 64-bit integers and add them.

In order to print the sum you'll need to have 64-bit division by 10, so you can convert a 64-bit integer into an ASCII string decimal representation of it (hint: 4=1234 mod 10 (then 123 = 1234 / 10), 3 = 123 mod 10 (then 12 = 123 / 10), 2 = 12 mod 10 (then 1 = 12 / 10), 1 = 1 mod 10 (then 0 = 1 / 10, stop)).

I'm not going to explain now how to do 64-bit division by 10 using 2 DIVs. Get the rest working first.