正数和负数(TASM) [英] An amount of positive and negative numbers (TASM)

查看:81
本文介绍了正数和负数(TASM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,

我正试图打造这个阵列的AVG:1742,1065,-67,-2988,-796,-1000,31,-67,-100, 1180

我相信我的方法是将数字从POS更改为NEG。

我需要计算上面的数组然后打印massege如果AVG​​是NEG或POS并且它总是打印AVG是POS,即使它不是。

这是我到目前为止的代码:

Hey Guys,
I'm trying to fint the AVG of this array : 1742,1065,-67,-2988,-796,-1000,31,-67,-100,1180
I belive my method to change the number from POS to NEG is worng.
my prog need's to calculate the above array then print massege if the AVG is NEG or POS, and it always print that the AVG is POS even though it's not.
here is my code so far:

; lab56.asm
;
    .MODEL SMALL
    .STACK 100h
    .DATA
AVG_NEG	 DB  'THE AVG IS NEG',13,10,'$'
AVG_POS	 DB  'THE AVG IS POS',13,10,'$'
INDEX    DB  'Numbers that are larger than the average are in indexes:',13,10,'$'
RES      DB  '                     ','$'
ARR	 	 DW  1742,1065,-67,-2988,-796,-1000,31,-67,-100,1180
Ten 	 DW  10
AVG      DW  0
temprint DB  '      ','$'
;Program start here:
	.CODE
	MOV AX,@DATA    ; DS can be written to only through a register
    MOV DS,AX       ; Set DS to point to data segment
	LEA SI, ARR
;
;   SUMUP
	MOV CX,10		;10 variables in array
Sum:
	MOV AX,[SI]
	CMP AX,0
	JG Pos_label
	XOR AX,0000000000000000b
	ADD AX,0000000000000001b
Pos_label:
	ADD AVG,AX
	ADD SI,2		;move to the next number
LOOP Sum
;	Divided by 10 to get the AVG
	CWD				; AX -> DX:AX
	IDIV Ten
	MOV AVG,AX
;	print
	
;	Check if NEG or POS
	CMP AVG,0
	JG Avg_label
	MOV AH,9       ; Set print option for int 21h
    MOV DX,OFFSET AVG_NEG		;  Set  DS:DX to point to AVG_NEG
    INT 21h
	JMP continue
Avg_label:
	MOV AH,9       ; Set print option for int 21h
    MOV DX,OFFSET AVG_POS		;  Set  DS:DX to point to AVG_POS
    INT 21h
continue:
;

;Program end's here:

     MOV AH,4Ch       ; Set terminate option for int 21h
     INT 21h       ; Return to DOS (terminate program)
     END 

推荐答案

'
AVG_POS DB'AVG IS POS', 13,10,'
' AVG_POS DB 'THE AVG IS POS',13,10,'


'
INDEX DB'大于平均值的数字在索引中:',13,10,'
' INDEX DB 'Numbers that are larger than the average are in indexes:',13,10,'


'
RES DB'','
' RES DB ' ','


这篇关于正数和负数(TASM)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆