.MODEL SMALL
.STACK 64
.DATA
LIST1 DB 1H,0ABH,2H,3AH,12H,0DAH
LIST2 DB 3H,7H,0BCH,0A8H,0C2H,0DAH
LIST3 DB 6 DUP (?)
.CODE
MAIN PROC FAR
MOV AX, @data
MOV DS, AX
MOV CX,6H
LEA SI,LIST1
LEA BX,LIST2
LEA DI,LIST3
A1: MOV AL,[SI]
ADD AL,BX
MOV [DI],AL
INC SI
INC BX
INC DI
LOOP A1
I want to compare list1 & list2 and put the greater number in list3. How to do that?
Here's an alternative
A1
loop. I think your setup instructions are OK. I'm assuming Intel syntax on operand ordering for instructions.In solving a problem like this, you can actually start by writing out the comments. If you were to take the comments above by themselves, they form the low level steps in English of what you want to do. Then you can translate those steps into the needed assembly language. You can then also optimize if needed.
[EDIT]
Note also that, as @Powerslave showed in his answer, you can shorten this a bit using the built-in x86 "string" instruction,
cmpsb
. That assumes source and destination lists are pointed to bysi
anddi
.For addition, the following puts the SUM of
LIST1
andLIST2
intoLIST3
. Note that you allocated bytes forLIST3
but when you sumLIST1
andLIST2
elements, you'll get an overflow if you keep them as bytes. So I will use words for the sum: