News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Simple Adding

Started by byte-aligned, May 10, 2005, 08:31:31 PM

Previous topic - Next topic

byte-aligned

Hi all, noob here  :green
I´m thinking about performing simple adding, for example I have two edit boxes, I convert those values to DWORD, using a2dw, then make the add, convert to ascii and print the result, I´m wrong?

The point that really interests me is making additions of large numbers, must I make the additions one byte a time and be aware of carring bit? How should I build an efficient adder that can add large numers (1-1000 for example)? Thanks in advance, great forum  :clap:

AeroASM

Are you using extended registers? (like eax, edx etc)

If so, then no problem until you get above 4000000000 roughly

byte-aligned

So in pseudo code:


Read User INPUT
Convert Input from ASCII to DWORD
Store in registers
Perform ADD
Convert from DWORD to ASCII
Read and Output result


Using for example A2DW and DW2A.

hutch--




    LOCAL value1  :DWORD
    LOCAL value2  :DWORD

  ; get your string data

    mov value1, sval(lpString1)    ; convert string to number
    add value1, sval(lpString2)     ; ad next converted number to it

  ; convert it back to string for display.
    print str$(eax),13,10
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

thomasantony

Quote from: hutch-- on May 10, 2005, 10:37:13 PM



    LOCAL value1  :DWORD
    LOCAL value2  :DWORD

  ; get your string data

    mov value1, sval(lpString1)    ; convert string to number
    add value1, sval(lpString2)     ; ad next converted number to it

  ; convert it back to string for display.
    print str$(eax),13,10

Don't you have to put the value in eax first before you do it your way? Ah.. even the masters make mistakes :bdg

Thomas :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

hutch--

Thomas,

I should have explained it a little better, the sval macro return in EAX so the value is already there.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

AeroASM

But it hasn't been added, you are just printing out the second value entered.

hutch--

Yerp,


    mov value1, sval(lpString1)    ; convert string to number
    add value1, sval(lpString2)     ; ad next converted number to it


The display should print "sstr$(value1)". Comes from coding directly into a forum text entry window.  :green
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

roticv

Quote from: byte-aligned on May 10, 2005, 08:31:31 PM

The point that really interests me is making additions of large numbers, must I make the additions one byte a time and be aware of carring bit? How should I build an efficient adder that can add large numers (1-1000 for example)? Thanks in advance, great forum  :clap:

You can work with adding dword at a time (Working with bytes is fine, but I think it is not speed efficient nor space efficient). There are some built in instruction that help you setttle the carry bit like adc/sbb. However you can make use of mmx/sse to do the addition as these adc/sbb is *slow*.

PS: 1-1000 is considered small unless you mean 10^1000  :toothy