I am new to nasm and I need to write oprogram that reads (user input) numbers 0-3000 and converts them to roman numbers. So the user inputs a number between 0-3000 and the the program converts it and outputs the corresponding roman number. Please help!!!

## Recommended Answers

So have you written the algorithm out on paper, or made any kind of sketch as to the steps you need to perform?

Or did you just dump the whole assignment on the board, along with all the "gimmetehcodez" bumps to similar threads that I'm seeing.

Read the …

you can check out this site
http://www.novaroma.org/via_romana/numbers.html
there is a converter on the right
it lets you convert between roman and numbers.
ypu can view the source of the page and get the algorithm.

and here is an improved one:

``````numtoroman proc uses ebx esi numin : DWORD, romout : DWORD
LOCAL numlen : DWORD
invoke lstrlen, numin
mov numlen, eax
mov eax, -1
mov ebx, numin
mov ecx, 0
mov edx, romout
@@:
inc eax
cmp byte ptr[ebx + eax], …``````

## All 9 Replies

So have you written the algorithm out on paper, or made any kind of sketch as to the steps you need to perform?

Or did you just dump the whole assignment on the board, along with all the "gimmetehcodez" bumps to similar threads that I'm seeing.

Read the forum rules - no free homework!

you can check out this site
http://www.novaroma.org/via_romana/numbers.html
there is a converter on the right
it lets you convert between roman and numbers.
ypu can view the source of the page and get the algorithm.

thank u I will try that

hey ive done the thing :P
ive included the program with the source in the attachment
and here is the conversion algorithm (ive written it fast so its pretty bulky but works properly):
(it can convert numbers up to 9999, but the range can be easily extended)

``````numtoroman proc uses ebx numin : DWORD, romout : DWORD
LOCAL numlen : DWORD
invoke lstrlen, numin
mov numlen, eax
mov eax, -1
mov ebx, numin
mov ecx, 0
mov edx, romout
@@:
inc eax
cmp byte ptr[ebx + eax], 0h
je lblret
cmp byte ptr[ebx + eax], '1'
jne lbl1
.if numlen == 1
mov byte ptr[edx + ecx], 'I'
.elseif numlen == 2
.if eax == 0
mov byte ptr[edx + ecx], 'X'
.else
mov byte ptr[edx + ecx], 'I'
.endif
.elseif numlen == 3
.if eax == 0
mov byte ptr[edx + ecx], 'C'
.elseif eax == 1
mov byte ptr[edx + ecx], 'X'
.else
mov byte ptr[edx + ecx], 'I'
.endif
.elseif numlen == 4
.if eax == 0
mov byte ptr[edx + ecx], 'M'
.elseif eax == 1
mov byte ptr[edx + ecx], 'C'
.elseif eax == 2
mov byte ptr[edx + ecx], 'X'
.else
mov byte ptr[edx + ecx], 'I'
.endif
.endif
inc ecx
jmp @B
lbl1:
cmp byte ptr[ebx+eax], '2'
jne lbl2
.if numlen == 1
mov word ptr[edx + ecx], 'II'
.elseif numlen == 2
.if eax == 0
mov word ptr[edx + ecx], 'XX'
.else
mov word ptr[edx + ecx], 'II'
.endif
.elseif numlen == 3
.if eax == 0
mov word ptr[edx + ecx], 'CC'
.elseif eax == 1
mov word ptr[edx + ecx], 'XX'
.else
mov word ptr[edx + ecx], 'II'
.endif
.elseif numlen == 4
.if eax == 0
mov word ptr[edx + ecx], 'MM'
.elseif eax == 1
mov word ptr[edx + ecx], 'CC'
.elseif eax == 2
mov word ptr[edx + ecx], 'XX'
.else
mov word ptr[edx + ecx], 'II'
.endif
.endif
add ecx, 2
jmp @B
lbl2:
cmp byte ptr[ebx+eax], '3'
jne lbl3
.if numlen == 1
mov word ptr[edx + ecx], 'II'
mov byte ptr[edx + ecx + 2], 'I'
.elseif numlen == 2
.if eax == 0
mov word ptr[edx + ecx], 'XX'
mov byte ptr[edx + ecx + 2], 'X'
.else
mov word ptr[edx + ecx], 'II'
mov byte ptr[edx + ecx + 2], 'I'
.endif
.elseif numlen == 3
.if eax == 0
mov word ptr[edx + ecx], 'CC'
mov byte ptr[edx + ecx + 2], 'C'
.elseif eax == 1
mov word ptr[edx + ecx], 'XX'
mov byte ptr[edx + ecx + 2], 'X'
.else
mov word ptr[edx + ecx], 'II'
mov byte ptr[edx + ecx + 2], 'I'
.endif
.elseif numlen == 4
.if eax == 0
mov word ptr[edx + ecx], 'MM'
mov byte ptr[edx + ecx + 2], 'M'
.elseif eax == 1
mov word ptr[edx + ecx], 'CC'
mov byte ptr[edx + ecx + 2], 'C'
.elseif eax == 2
mov word ptr[edx + ecx], 'XX'
mov byte ptr[edx + ecx + 2], 'X'
.else
mov word ptr[edx + ecx], 'II'
mov byte ptr[edx + ecx + 2], 'I'
.endif
.endif
add ecx, 3
jmp @B
lbl3:
cmp byte ptr[ebx+eax], '4'
jne lbl4
.if numlen == 1
mov word ptr[edx + ecx], 'VI'
.elseif numlen == 2
.if eax == 0
mov word ptr[edx + ecx], 'LX'
.else
mov word ptr[edx + ecx], 'VI'
.endif
.elseif numlen == 3
.if eax == 0
mov word ptr[edx + ecx], 'DC'
.elseif eax == 1
mov word ptr[edx + ecx], 'LX'
.else
mov word ptr[edx + ecx], 'VI'
.endif
.elseif numlen == 4
.if eax == 0
mov dword ptr[edx + ecx], 'MMMM'
add ecx, 2
.elseif eax == 1
mov word ptr[edx + ecx], 'DC'
.elseif eax == 2
mov word ptr[edx + ecx], 'LX'
.else
mov word ptr[edx + ecx], 'VI'
.endif
.endif
add ecx, 2
jmp @B
lbl4:
cmp byte ptr[ebx+eax], '5'
jne lbl5
.if numlen == 1
mov byte ptr[edx + ecx], 'V'
.elseif numlen == 2
.if eax == 0
mov byte ptr[edx + ecx], 'L'
.else
mov byte ptr[edx + ecx], 'V'
.endif
.elseif numlen == 3
.if eax == 0
mov byte ptr[edx + ecx], 'D'
.elseif eax == 1
mov byte ptr[edx + ecx], 'L'
.else
mov byte ptr[edx + ecx], 'V'
.endif
.elseif numlen == 4
.if eax == 0
mov dword ptr[edx + ecx], 'MMMM'
mov byte ptr[edx + ecx + 4], 'M'
add ecx, 4
.elseif eax == 1
mov byte ptr[edx + ecx], 'D'
.elseif eax == 2
mov byte ptr[edx + ecx], 'L'
.else
mov byte ptr[edx + ecx], 'V'
.endif
.endif
inc ecx
jmp @B
lbl5:
cmp byte ptr[ebx+eax], '6'
jne lbl6
.if numlen == 1
mov word ptr[edx + ecx], 'IV'
.elseif numlen == 2
.if eax == 0
mov word ptr[edx + ecx], 'XL'
.else
mov word ptr[edx + ecx], 'IV'
.endif
.elseif numlen == 3
.if eax == 0
mov word ptr[edx + ecx], 'CD'
.elseif eax == 1
mov word ptr[edx + ecx], 'XL'
.else
mov word ptr[edx + ecx], 'IV'
.endif
.elseif numlen == 4
.if eax == 0
mov dword ptr[edx + ecx], 'MMMM'
mov word ptr[edx + ecx + 4], 'MM'
add ecx, 4
.elseif eax == 1
mov word ptr[edx + ecx], 'CD'
.elseif eax == 2
mov word ptr[edx + ecx], 'XL'
.else
mov word ptr[edx + ecx], 'IV'
.endif
.endif
add ecx, 2
jmp @B
lbl6:
cmp byte ptr[ebx+eax], '7'
jne lbl7
.if numlen == 1
mov word ptr[edx + ecx], 'IV'
mov byte ptr[edx + ecx + 2], 'I'
.elseif numlen == 2
.if eax == 0
mov word ptr[edx + ecx], 'XL'
mov byte ptr[edx + ecx + 2], 'X'
.else
mov word ptr[edx + ecx], 'IV'
mov byte ptr[edx + ecx + 2], 'I'
.endif
.elseif numlen == 3
.if eax == 0
mov word ptr[edx + ecx], 'CD'
mov byte ptr[edx + ecx + 2], 'C'
.elseif eax == 1
mov word ptr[edx + ecx], 'XL'
mov byte ptr[edx + ecx + 2], 'X'
.else
mov word ptr[edx + ecx], 'IV'
mov byte ptr[edx + ecx + 2], 'I'
.endif
.elseif numlen == 4
.if eax == 0
mov dword ptr[edx + ecx], 'MMMM'
mov word ptr[edx + ecx + 4], 'MM'
mov byte ptr[edx + ecx + 6], 'M'
add ecx, 4
.elseif eax == 1
mov word ptr[edx + ecx], 'CD'
mov byte ptr[edx + ecx + 2], 'C'
.elseif eax == 2
mov word ptr[edx + ecx], 'XL'
mov byte ptr[edx + ecx + 2], 'X'
.else
mov word ptr[edx + ecx], 'IV'
mov byte ptr[edx + ecx + 2], 'I'
.endif
.endif
add ecx, 3
jmp @B
lbl7:
cmp byte ptr[ebx+eax], '8'
jne lbl8
.if numlen == 1
mov dword ptr[edx + ecx], 'IIIV'
.elseif numlen == 2
.if eax == 0
mov dword ptr[edx + ecx], 'XXXL'
.else
mov dword ptr[edx + ecx], 'IIIV'
.endif
.elseif numlen == 3
.if eax == 0
mov dword ptr[edx + ecx], 'CCCD'
.elseif eax == 1
mov dword ptr[edx + ecx], 'XXXL'
.else
mov dword ptr[edx + ecx], 'IIIV'
.endif
.elseif numlen == 4
.if eax == 0
mov dword ptr[edx + ecx], 'MMMM'
mov dword ptr[edx + ecx + 4], 'MMMM'
add ecx, 4
.elseif eax == 1
mov dword ptr[edx + ecx], 'CCCD'
.elseif eax == 2
mov dword ptr[edx + ecx], 'XXXL'
.else
mov dword ptr[edx + ecx], 'IIIV'
.endif
.endif
add ecx, 4
jmp @B
lbl8:
cmp byte ptr[ebx+eax], '9'
jne lbl9
.if numlen == 1
mov word ptr[edx + ecx], 'XI'
.elseif numlen == 2
.if eax == 0
mov word ptr[edx + ecx], 'CX'
.else
mov word ptr[edx + ecx], 'XI'
.endif
.elseif numlen == 3
.if eax == 0
mov word ptr[edx + ecx], 'MC'
.elseif eax == 1
mov word ptr[edx + ecx], 'CX'
.else
mov word ptr[edx + ecx], 'XI'
.endif
.elseif numlen == 4
.if eax == 0
mov dword ptr[edx + ecx], 'MMMM'
mov dword ptr[edx + ecx + 4], 'MMMM'
mov byte ptr[edx + ecx + 8], 'M'
add ecx, 7
.elseif eax == 1
mov word ptr[edx + ecx], 'MC'
.elseif eax == 2
mov word ptr[edx + ecx], 'CX'
.else
mov word ptr[edx + ecx], 'XI'
.endif
.endif
add ecx, 2
jmp @B
lbl9:
cmp byte ptr[ebx+eax], '0'
jne lblret
jmp @B
lblret:
mov byte ptr[edx+ecx], 0h
ret
numtoroman endp``````
commented: Answer on a plate solution, no "help" at all in improving the understanding of the OP -4

and here is an improved one:

``````numtoroman proc uses ebx esi numin : DWORD, romout : DWORD
LOCAL numlen : DWORD
invoke lstrlen, numin
mov numlen, eax
mov eax, -1
mov ebx, numin
mov ecx, 0
mov edx, romout
@@:
inc eax
cmp byte ptr[ebx + eax], 0h
je lblret
cmp byte ptr[ebx + eax], '1'
jne lbl1
mov esi, numlen
sub esi, eax
.if esi == 1
mov byte ptr[edx + ecx], 'I'
.elseif esi == 2
mov byte ptr[edx + ecx], 'X'
.elseif esi == 3
mov byte ptr[edx + ecx], 'C'
.elseif esi == 4
mov byte ptr[edx + ecx], 'M'
.endif
inc ecx
jmp @B
lbl1:
cmp byte ptr[ebx+eax], '2'
jne lbl2
mov esi, numlen
sub esi, eax
.if esi == 1
mov word ptr[edx + ecx], 'II'
.elseif esi == 2
mov word ptr[edx + ecx], 'XX'
.elseif esi == 3
mov word ptr[edx + ecx], 'CC'
.elseif esi == 4
mov word ptr[edx + ecx], 'MM'
.endif
add ecx, 2
jmp @B
lbl2:
cmp byte ptr[ebx+eax], '3'
jne lbl3
mov esi, numlen
sub esi, eax
.if esi == 1
mov word ptr[edx + ecx], 'II'
mov byte ptr[edx + ecx + 2], 'I'
.elseif esi == 2
mov word ptr[edx + ecx], 'XX'
mov byte ptr[edx + ecx + 2], 'X'
.elseif esi == 3
mov word ptr[edx + ecx], 'CC'
mov byte ptr[edx + ecx + 2], 'C'
.elseif esi == 4
mov word ptr[edx + ecx], 'MM'
mov byte ptr[edx + ecx + 2], 'M'
.endif
add ecx, 3
jmp @B
lbl3:
cmp byte ptr[ebx+eax], '4'
jne lbl4
mov esi, numlen
sub esi, eax
.if esi == 1
mov word ptr[edx + ecx], 'VI'
.elseif esi == 2
mov word ptr[edx + ecx], 'LX'
.elseif esi == 3
mov word ptr[edx + ecx], 'DC'
.elseif esi == 4
mov dword ptr[edx + ecx], 'MMMM'
add ecx, 2
.endif
add ecx, 2
jmp @B
lbl4:
cmp byte ptr[ebx+eax], '5'
jne lbl5
mov esi, numlen
sub esi, eax
.if esi == 1
mov byte ptr[edx + ecx], 'V'
.elseif esi == 2
mov byte ptr[edx + ecx], 'L'
.elseif esi == 3
mov byte ptr[edx + ecx], 'D'
.elseif esi == 4
mov dword ptr[edx + ecx], 'MMMM'
mov byte ptr[edx + ecx + 4], 'M'
add ecx, 4
.endif
inc ecx
jmp @B
lbl5:
cmp byte ptr[ebx+eax], '6'
jne lbl6
mov esi, numlen
sub esi, eax
.if esi == 1
mov word ptr[edx + ecx], 'IV'
.elseif esi == 2
mov word ptr[edx + ecx], 'XL'
.elseif esi == 3
mov word ptr[edx + ecx], 'CD'
.elseif esi == 4
mov dword ptr[edx + ecx], 'MMMM'
mov word ptr[edx + ecx + 4], 'MM'
add ecx, 4
.endif
add ecx, 2
jmp @B
lbl6:
cmp byte ptr[ebx+eax], '7'
jne lbl7
mov esi, numlen
sub esi, eax
.if esi == 1
mov word ptr[edx + ecx], 'IV'
mov byte ptr[edx + ecx + 2], 'I'
.elseif esi == 2
mov word ptr[edx + ecx], 'XL'
mov byte ptr[edx + ecx + 2], 'X'
.elseif esi == 3
mov word ptr[edx + ecx], 'CD'
mov byte ptr[edx + ecx + 2], 'C'
.elseif esi == 4
mov dword ptr[edx + ecx], 'MMMM'
mov word ptr[edx + ecx + 4], 'MM'
mov byte ptr[edx + ecx + 6], 'M'
add ecx, 4
.endif
add ecx, 3
jmp @B
lbl7:
cmp byte ptr[ebx+eax], '8'
jne lbl8
mov esi, numlen
sub esi, eax
.if esi == 1
mov dword ptr[edx + ecx], 'IIIV'
.elseif esi == 2
mov dword ptr[edx + ecx], 'XXXL'
.elseif esi == 3
mov dword ptr[edx + ecx], 'CCCD'
.elseif esi == 4
mov dword ptr[edx + ecx], 'MMMM'
mov dword ptr[edx + ecx + 4], 'MMMM'
add ecx, 4
.endif
add ecx, 4
jmp @B
lbl8:
cmp byte ptr[ebx+eax], '9'
jne lbl9
mov esi, numlen
sub esi, eax
.if esi == 1
mov word ptr[edx + ecx], 'XI'
.elseif esi == 2
mov word ptr[edx + ecx], 'CX'
.elseif esi == 3
mov word ptr[edx + ecx], 'MC'
.elseif esi == 4
mov dword ptr[edx + ecx], 'MMMM'
mov dword ptr[edx + ecx + 4], 'MMMM'
mov byte ptr[edx + ecx + 8], 'M'
add ecx, 7
.endif
add ecx, 2
jmp @B
lbl9:
cmp byte ptr[ebx+eax], '0'
jne lblret
jmp @B
lblret:
mov byte ptr[edx+ecx], 0h
ret
numtoroman endp``````

thank u very very much!!! :)

ure welcom :)

@low_coder
> hey ive done the thing
Congratulations, you've "helped" someone to a grade they don't deserve, and won't be able to replicate in future.

Are you going to do ALL their homework from now on?

This applies to helpers, as well as those asking for help.
http://www.daniweb.com/forums/announcement125-2.html

oh ok.
but ive done it because i was interested in this problem (project).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.