views:

387

answers:

2

Hi by using the strings

  promptl BYTE "Enter a signed integer: ",0
  prompt2 BYTE "The sum of the integers is: ",0

will It prompt a user for two integers using assembly language and how do I add the two integers using Assembly language?

+2  A: 

My 6502 is a little rusty (no, not the chip itself, my skills)*, but something like this? [You didn't say which assembly language you were using :-) ]

LDX #prompt1
LDA #prompt2
CLC
ADC
BCS &overflow
RTS
.overflow
' handle the overflow here..
  • This joke is (c) mjv , 2010
monojohnny
I am new at this ..not sure but the book is entitled assembly language for intel-based computers
So Assembly Language is little more than a human-readable version of machine-code. Machine-code is what microprocessors understand - and each different type of microprocessor has its own machine code (and therefore assembly language). If you are trying to program a intel-based computer in assembly, you need to look up the x86 (probably) instruction set: and read up a bit on how a microprocessor is organized. For your task you will probably need to find a 'load register' instruction, an 'ADD' instruction and some other instructions to deal with the carry bit.
monojohnny
And even though I was kind of joking posting 6502 machine code (the 6502 is a very old 8-bit proc), and probably I got the instructions wrong - the general outline of what you need to do is probably not that far off: but you will need to lookup the Intel (probably x86) instruction set to do this properly.
monojohnny
@mjv - I was tempted to edit my wording in my answer, but that would just spolil your joke :-)
monojohnny
@monojohnny: "rusty" comment removed. Please edit as you see fit ;-)
mjv
+2  A: 

The BYTE directive is not an assembly instruction per se, it is merely a way to ask the assembler to reserve and optionally initialize a memory location for a byte or an array of bytes. Also, this memory location gets associated with a label (a variable name) for future reference in the program.

So...

  promptl BYTE "Enter a signed integer: ",0

will merely define the prompt1 variable to contain this string and to be terminated by an (extra) byte containing 0. It will not output any prompt anywhere.

If you wish to display this message, you'll typically need to invoke a primitive function of the system to do this. In the MS-DOS world a lot of these basic services are rendered by calls to the famous INT $21 (Interrupt #21), having previously loaded the A register with a numeric code indicating the desired "service" (along with additional registers etc. depending on the particular "service" desired).

So, in the MS-DOS world, the beginning of your program could look something like the following. You'd then need to convert the input value to an integer, store it to a work variable, prompt the user anew, get another value, convert it, and finally add these two values. Of course, you'd probably introduce subroutines, so that you can handle repetitive tasks without too much code duplication.

prompt1 byte "Enter a signed integer: "   ; btw in most assemblers the explicit added null char is not needed.
inputStr db 50,?      ; defines a variable where to store the user's response (up to 50 bytes)

; prompt the user
        mov dx, offset prompt1
        mov ah, 9
        int 21h
; input a string: 
        mov dx, offset inputStr
        mov ah, 0ah
        int 21h

;etc...
mjv