For science fair, I need three programs that count to 50,000 and output each number as they do, I need one in c++, one in java, and one in assembly. I have the c++ and java programs, but I don’t see what I’m doing wrong for my assembly code:
[org 0x100]
[bits 32]
mov ax, 0
mov bx, target
jmp start
start:
mov cx, 0x01
add ax, cx
mov dx, ax
mov ah, 09
int 0x21
mov ax, dx
cmp ax, bx
jg term
jmp start
term:
mov dx, msgT
mov ah, 09
int 0x21
mov ah, 00
int 0x21
msgT db 'Terminating'
target dw 50000
I am using the assembler NASM, and right now, it counts to 50,000 but doesn’t output each number as it calculates them.
Copied from my comment:
If you’re trying to make a 16-bit MS-DOS com file, you should be using [bits 16]. And as @Vlad says AH=09h takes a string in DX not a number (see e.g. here on how to convert a number to string, also note that you’ll have to $-terminate the string instead of NUL-terminate it).
Some other things:
mov bx, targetmoves the address oftargettobx. You wanted:mov bx, [target].jg termis branching based on signed comparison (you’re effectively comparingaxto-15536). You wantja term.The basic structure of your program should be something like this: