Home > other >  Assembly language input three Numbers of the sum of positive and negative number
Assembly language input three Numbers of the sum of positive and negative number

Time:11-03

The number of digits in a negative number has been output all
Positive will output the sum of all digital stitching inspection for a long time also don't see
Assembly is so hard I'm dead ball ball, save me



DATAS SEGMENT
; The input data code
Intig db ah 0, 0 dh, 'both Please input a number: $'
Dh outtig1 db 0, 0 ah, 'The number of negative Numbers is: $'
Dh outtig2 db 0, 0 ah, 'The sum of positive Numbers is: $'
N the dw 10
Dw 10000100 x 0100,10,1
Dplus dw 80,0,80 dup (0)
D DW 0
A DW 0
E dw 0
DATAS ENDS

Sports a SEGMENT
; Enter the stack code
Sports a ENDS

CODES SEGMENT
ASSUME CS: CODES, DS: DATAS, SS: sports a
START:
MOV AX, DATAS
MOV DS, AX
; Enter the code code

MOV D, 0

The MAIN PROC NEAR
Cx, mov 3
L10:
Lea dx, intig
Mov ah, 9
Int 21 h
Call the INPUT
Dec cx
JNZ l10


Lea dx, outtig1
Mov ah, 9
Int 21 h

The add e, 30 h
Mov dx, e
Mov ah, 2
Int 21 h

MOV di, 2
MOV AX, 0
MOV SI, AX
AGAIN:
The ADD AX, dplus [SI]
The ADD SI, 2
Dec di
MOV d, AX
JNZ AGAIN


Lea dx, outtig2
Mov ah, 9
Int 21 h

Mov ax, d
Mov dx, 0

Mov bx, 10000
Div bx
Mov d, dx

The add ax, '0'
Mov dx, ax
Mov ah, 2
Int 21 h

Mov ax, d
Mov dx, 0

Mov bx, 1000
Div bx
Mov d, dx

The add ax, '0'
Mov dx, ax
Mov ah, 2
Int 21 h

Mov ax, d
Mov dx, 0

Mov bx, 100
Div bx
Mov d, dx

The add ax, '0'
Mov dx, ax
Mov ah, 2
Int 21 h

Mov ax, d
Mov dx, 0

Mov bx, 10
Div bx
Mov d, dx

The add ax, '0'
Mov dx, ax
Mov ah, 2
Int 21 h

Mov ax, d
Mov dx, 0

Mov bx, 1
Div bx
Mov d, dx

The add ax, '0'
Mov dx, ax
Mov ah, 2
Int 21 h



RET

The main endp

INPUT the PROC NEAR
L1:

Mov ah, 1

Int h; AL=input digital ASCII

CMP al, 0 dh; 0 dh is the enter

Jz L2

CMP al, '-'
Je l3
CMP AL, '0'
Jl L2
CMP AL, '9'
Jg L2



Sub al, 30 h

Mov ah, 0

XCHG bx, ax

The mul n

The add bx, ax

JMP L1

L2:

Mov dplus [0 + si], bx
The add si, 2

L3:
Mov ah, 1
Int h; AL=input digital ASCII

CMP al, 0 dh; 0 dh is the enter
Jz L4

CMP AL, '0'
Jl L4
CMP AL, '9'
Jg L4


Sub al, 30 h

Mov ah, 0

XCHG bx, ax

The mul n

The add bx, ax

JMP L3

L4:
Inc e
RET
INPUT ENDP


MOV AH, 4 ch
INT 21 h
CODES ENDS
The END START



















CodePudding user response:

No INPUT data right, INPUT BX s first in the procedure, add after the positive part of the carriage return and then should return to the ret does not continue to the negative part of the below, the final end of the program is a problem with the ret'd better use DOS interrupt AH=4 ch function call,

CodePudding user response:

Positive part of the carriage return should not add and then ret return is why
Every time and lose positive to knock twice enter negative knock again is the reason why the above

CodePudding user response:

Why, one sum not topics; And then ret but not like you don't keep the following plan part is negative, to return the result of twice,
  • Related