# [General]Microprocessor small problem solving

Status
Not open for further replies.

#### a_rishi

##### Newbie level 2
Hi Everybody

I need to add even numbers and odd numbers separately and store the result in the Even sum and Odd sum register respectively.

I'm trying a code as follow. I'm a complete novice in microprocessor.

Code ASM - [expand]1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
. model small

.data

ARRAY dB 45H, 07H, 61H, 47H, 17H, 16H, 08H, 55H, 63H, 74H

Even Sum dB ?

Odd Sum dB ?

.Code

START: MOV AX, @data
MOV DS, AX
MOV DI, 00H
MOV DI,00H
MOV CL, 0AH

LABEL: MOV BL, ARRAY [DI]
MOV AL,BL
RCR AL,1
JNC EV
INC DI
DEC CL
JC OD

END LABEL
END

EV: MOV AL, DL

MOV Sum, DH

END EV
END

Last edited by a moderator:

#### KlausST

##### Super Moderator
Staff member
Hi,

What controller?

The routine "OD" is completely missing.

What do you try to achieve with this?
Code:
MOV DI, 00H
MOV DI,00H
It seems to me this is a first try from "zero".

Please try to go through tutorials.
Then try to do your changes on existing code.
After you understand what happens, then try to write your own code. May be also starting from an existing code.

Klaus

#### Gorgon

##### Full Member level 6
Any reason each sum should only be one byte?
Your allocation of sums look to be in code memory, not RAM. I would think DS is a better definition parameter, and you need to add the size of each sum.

The syntax is also odd, but since we don't know the assembler it's early to say.

#### milan.rajik

##### Banned
According to the asm code it is x86 asm code and I guess he is using MASM.

#### a_rishi

##### Newbie level 2
According to the asm code it is x86 asm code and I guess he is using MASM.
Hi Everybody

Yes it is x86 code.

The code is not complete. If you could write a small code such that the array of numbers be added separately (i.e odd and even number) and store the even sum in a register and the odd sum in another register.

With respect to the above code, RCR (Rotate to the right with carry) is used to check the least significant bit (0 for even and jump to a sepaarte code EV for addition, whereas for 1 it jump to Odd code OD for sum).

Thanks

Status
Not open for further replies.