开发者

Using the prompt for integers in assembly language

promptl BYTE "Ent开发者_C百科er 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?


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...


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜