I have been working on a project in Intel assembly until I hit a bump and I can't seem to get myself out of a hole. I realize that this is homework, and I don't expect anyone to do my work for me. However, a little help would definitely be nice. I think I will be able to figure out the last procedure if PrintNumber gets figured out. However, I don't understand what to do for these:
;determine the size of binary value
;set index to size
;move '$' to storage array offset index
;append ascii bits to remainder

Thanks for the help.

Pseudocode
Main procedure that will use three procedures to get any two integer values, find their greatest common divisor, and display the two integers and their GCD to display screen. It should allow the user to run the program for any number of pairs of integers until the user indicates that they do not have any more data to process.

GetNumber (ASCII to Binary) procedure

set character count to zero
get a character from the keyboard
while character is not the carriage return
store character in input array
increment character count
get a character from the keyboard
set multiplier to 1
set index to character count minus 1
loop character count times
get character at offset index
remove ASCII bits (using and mask)
multiply by multiplier
add to binary value
multiply the multiplier by 10
decrement the index

PrintNumber (Binary to ASCII) procedure

determine the size of the binary value
set index to size
move '$' to storage array offset index
decrement index
while binary value > 10
divide binary value by 10
append ASCII bits to remainder
move ASCII remainder to storage array offset index
decrement index
append ASCII bits to last digit
move ASCII value to storage array offset index
set dx register with starting address of storage array
display ASCII string (FC = 09h, int 21h)

GreatestCommonDivisor procedure
get first number
get second number
while first number != to second number
if second number is > first number
second number = second number - first number
else
first number = first number - second number
GCD = first number ( or second number)
display GCD value

What I have so far:

.MODEL SMALL
.STACK 100

.DATA
mult db ?
input dw ?

.CODE
Main PROC
mov ax,@data
mov ds,ax			;set DS to point to the data segment

mov ax, 4C00h
int 21h
Main ENDP

GetNumber PROC

mov cx, 0				;set char count to 0

mov ah, 01h				;obtain char from sdin
int 21h

mov bx, 0Dh
WHILE bx != ah				;while loop
  mov input, ah				;store char in input
  inc cx					;inc cx
  mov ah, 01h				;get another char from sdin
  int 21h
ENDM						;end while

mov mult, 1					;set mult to 1
mov bx, cx - 1				;set index to cx - 1

L2:							;fixed duration loop
 mov al, OFFSET bl			;get char at offset index
 and al, 000Fh				;remove ASCII bits via and mask
 mul mult					;multiply x multiplier
 mov ah, 0
 add al, ah				    ;+ to Binary value
 mov al, 10
 mov bl, mult
 mul bl						;multiplier x 10
 dec bx						;dec index
 loop L2
 RET
GetNumber ENDP

PrintNumber PROC
;determine the size of binary value
;set index to size
;move '$' to storage array offset index
dec bx						;dec index

WHILE al > 10				;while loop while binary value > 10 
div al, 10					;% binary value by 10
	;append ascii bits to remainder
	;move ascii remainder to storage array offset index
dec bx						;dec index
ENDM
;append ascii bits to last digit
;mov ascii value to storage array offset index
;set dx register with starting address of storage array
;mov FC, 09h					;display ascii string
;int 21h						
RET
PrintNumber ENDP

GreatestCommonDenom PROC
;get first #
;get second #
;while loop while first # != to second #
	; if second # > first #
		;second # = second # - first#
	;else
		;first # = first # - second #
;GCD = first or second #
;display GCD
RET
GreatestCommonDenom ENDP
END Main

Recommended Answers

All 2 Replies

> ;determine the size of binary value
In a loop, you
- divide the number by 10
- increment a count

When you reach zero, your count is how many digits the number needs to be printed.

IIRC, the div instruction stores the division result in one register, and the modulus result in another. You'll need that for step 2.

> ;determine the size of binary value
In a loop, you
- divide the number by 10
- increment a count

When you reach zero, your count is how many digits the number needs to be printed.

IIRC, the div instruction stores the division result in one register, and the modulus result in another. You'll need that for step 2.

Ah cool, thank you very much.

Be a part of the DaniWeb community

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