Author Topic: CMP command doesn't seem to be working  (Read 10573 times)

Offline robinq

  • Jr. Member
  • *
  • Posts: 3
CMP command doesn't seem to be working
« on: November 21, 2018, 07:13:48 PM »
Hi,
I have started learning Assembler and as a project I want to make a program that will point prime numbers in selected range. I was pretty sure that I have done everything right, but my code doesn't work:

Code: [Select]
ORG 100H
START:
MOV AH, 1
INT 21H
MOV BX, AX    ;I store left range set in BX

MOV AH, 1
INT 21H
MOV DX, AX    ;I put right set in DX

MOV CX, DX
SUB CX, BX
INC CX           ;CX has a number of numbers to check
MOV DX, 0
JMP CHECK

CHECK:
CMP BX, [PRIME]
JE ADPRIM
CMP BX, [PRIME + 1]
JE ADPRIM
CMP BX, [PRIME + 2]
JE ADPRIM
CMP BX, [PRIME + 3]
JE ADPRIM
INC BX
LOOP CHECK
JMP WRITE

ADPRIM:
INC DX     ;DX is a number of prime numbers
PUSH BX   ;I want to push all prime numbers on stack and write them later
INC BX
DEC CX
JMP CHECK

PRIME DB 50, 51, 53, 55

The problem is, ADPRIM part is never seems to activate and both DX and stack are empty when arriving at WRITE. What have I done wrong?
« Last Edit: November 21, 2018, 07:23:54 PM by robinq »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: CMP command doesn't seem to be working
« Reply #1 on: November 21, 2018, 07:34:17 PM »
I don't see a "cmp" anywhere.

Best,
Frank


Offline robinq

  • Jr. Member
  • *
  • Posts: 3
Re: CMP command doesn't seem to be working
« Reply #2 on: November 21, 2018, 08:01:57 PM »
There are four comparisons in "Check" segment (you have to scroll the code a little)  :)

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: CMP command doesn't seem to be working
« Reply #3 on: November 21, 2018, 08:24:32 PM »
Oops. My bad. Sorry.

bx is a 16 bit register. "prime" is a list of bytes. Try bl.

Best,
Frank


Offline robinq

  • Jr. Member
  • *
  • Posts: 3
Re: CMP command doesn't seem to be working
« Reply #4 on: November 21, 2018, 09:48:56 PM »
OK, so it was that easy. Now it works. Thank you a lot!
« Last Edit: November 21, 2018, 10:00:28 PM by robinq »