freddyvorhees 0 Newbie Poster

found this code here: http://www.codeguru.com/forum/showthread.php?t=435239

.model small
.data
	q1 db "ENTER FIRST NUMBER: $"
	num1 db 5, ?, 5 dup(?)
	space db 10, "", "$"
	q2 db "ENTER SECOND NUMBER: $"
	num2 db 5, ?, 5 dup(?)
	msg db 13, 10, "ANSWER: ", "$"
	answer db "0000", 13, 10, "$"
	temp dw ?
	temp1 dw ?
	temp2 dw ?
	sum dw ?

.stack 64	
.code

	AskStore macro q, num
		mov dx, offset q ;PRINTS QUESTION
		mov ah, 09h
		int 21h
	
		mov dx, offset num ;GETS STRING AND STORES IT IN BUFFER
		mov ah, 0Ah
		int 21h
	
		mov bx, offset num ;FINDS END OF STRING
		add bx, 1
		add bl, [bx]
		add bx, 1
	
		mov al, '$' ;APPENDS $ TO END OF STRING
		mov [bx], al
	endm
	
	Pano proc ;CONVERTS STRING TO HEX
		add bx, 1
		mov cl, [bx]
		
		cmp cl, 4
		je pork
		cmp cl, 3
		je tri
		cmp cl, 2
		je dos
		cmp cl, 1
		je uno
		jmp tapos
		
			pork:
				call Convict
				
				mov si, 1000h
				mul si
				add temp, ax
			tri:
				call Convict
				
				mov si, 100h
				mul si
				add temp, ax
			dos:
				call Convict
				
				mov si, 10h
				mul si
				add temp, ax
			uno:
				call Convict
				
				add temp, ax
			tapos:
				ret
	endp
	
	Convict proc ;CONVERTS STRING TO HEX
		add bx, 1
		mov al, [bx]
	
		mov ah, 0
		cmp al, 41h
		jge f2
		
		f1:
			sub al, 30h
			jmp tpos
		
		f2:
			sub al, 41h
			add al, 0Ah
			
		tpos:
			ret
	endp
	
	Balik proc ;RETURNS HEX TO STRING FORMAT
	    cmp sum, 8000h
		jge thou
		cmp sum, 1000h
		jge thou
		
		cmp sum, 100h
		jge hun
		
		cmp sum, 10h
		jge ten
		
		cmp sum, 1h
		jge one
		jmp tapus
		
		thou:
			mov dx, 0
			
			mov si, 1000h
			div si
			
			cmp ax, 10
			jge letter
		
			numero:
				add ax, 30h
				jmp tapows
			letter:
				add ax, 37h
			tapows:
				mov answer[0], al	
				
			mov ax, dx
		hun:
			mov dx, 0
			
			mov si, 100h
			div si
			
			cmp ax, 10
			jge lettero
		
			numerow:
				add ax, 30h
				jmp tapowso
			lettero:
				add ax, 37h
			tapowso:
				mov answer[1], al
				
			mov ax, dx
		ten:
			mov dx, 0
			
			mov si, 10h
			div si
			
			cmp ax, 10
			jge letterk
		
			numerok:
				add ax, 30h
				jmp tapowsk
			letterk:
				add ax, 37h
			tapowsk:
				mov answer[2], al
				
			mov ax, dx
		one:
			mov dx, 0
			
			cmp ax, 10
			jge letterl
		
			numerol:
				add ax, 30h
				jmp tapowsl
			letterl:
				add ax, 37h
			tapowsl:
				mov answer[3], al
		tapus:
			ret
	endp
start:

	mov ax, @data
	mov ds, ax

	AskStore q1, num1
	
	mov bx, offset temp
	mov cx, 0
	mov [bx], cx
	
	mov bx, offset num1
	
	call Pano
	
	mov bx, offset temp
	mov cx, [bx]
	mov bx, offset temp1
	mov [bx], cx
	
	mov dx, offset space
	mov ah, 09h
	int 21h
	
	AskStore q2, num2
	
	mov bx, offset temp
	mov cx, 0
	mov [bx], cx
	
	mov bx, offset num2
	
	call Pano
	
	mov bx, offset temp
	mov cx, [bx]
	mov bx, offset temp2
	mov [bx], cx
	
	mov ax, temp1
	mov bx, temp2
	add ax, bx
	mov sum, ax
	mov bx, offset sum
	mov ax, [bx]
		
	call Balik	
	
	mov dx, offset msg ;PRINTS SUM MESSAGE
	mov ah, 09h
	int 21h
	
	mov dx, offset answer ;PRINTS ANSWER
	mov ah, 09h
	int 21h
	
	mov ah, 4ch
	int 21h
	
end start

can you explain how the code works.thank you

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.