4 Replies - 4958 Views - Last Post: 15 November 2009 - 12:11 AM

#1 FCW1073  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 14-November 09

8086 assembler help

Posted 14 November 2009 - 10:32 PM

Hello all i am new to assemble and have a assignment im having trouble with tried all week to figure it out and been stuck. I would like to mention that a fellow friend of the site has asked but after checking a bit of the site i have found words i will not use ever on this site. Anyway i need two type two numbers and have the emu8086 tell me the smaller of the two numbers. I have try a few different ways to fix it well let me tell you the problem it only types the first number you type.

include 'emu8086.inc'

org  100h; set location counter to 100h

jmp CodeStart

DataStart:
	promptMsg db "enter a number> ", 0
	minMsg db "the smallest number is ", 0
	newline db 13, 10, 0
	num1 dw ?
	num2 dw ?

CodeStart:
	
   ; prompt user to enter in a number
	mov si, offset promptMsg
	call print_string
	
   ; read in the number into cx
	call scan_num
	
   ; move the number to a variable
	mov num1, cx
	
   ; advance cursor to the next line
	mov si, offset newline
	call print_string

   ; prompt user to enter in a number
	mov si, offset promptMsg
	call print_string
	
   ; read in the number into cx
	call scan_num
	
   ; move the number to a variable
	mov num2, cx
	
   ; advance cursor to the next line
	mov si, offset newline
	call print_string

   ; print min message
	mov si, offset minMsg
	call print_string

	mov ax, num1

	call print_num	
	
	EndLabel:
	ret
	
DEFINE_PRINT_STRING	
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS


Here is the orignal form of the code.

Here is when i modified it.
org  100h; set location counter to 100h
jmp CodeStart
DataStart:
	promptMsg db "enter a number> ", 0
	minMsg db "the smallest number is ", 0
	newline db 13, 10, 0
	num1 dw ?
	num2 dw ?
CodeStart:
	
   ; prompt user to enter in a number
	mov si, offset promptMsg
	call print_string
	
   ; read in the number into cx
	call scan_num
	
   ; move the number to a variable
	mov num1, cx
	
   ; advance cursor to the next line
	mov si, offset newline
	call print_string
   ; prompt user to enter in a number
	mov si, offset promptMsg
	call print_string
	
   ; read in the number into cx
	call scan_num
	
   ; move the number to a variable
	mov num2, cx
	
   ; advance cursor to the next line
	mov si, offset newline
	call print_string
   ; print min message
	mov si, offset minMsg
	call print_string
	mov ax, num1
	
		
	cmp ax, num2
jmp CodeStart:
	jle num1, ax 
	
	mov ax, num2
	
	call print_num	
	
	EndLabel:
	ret
	
DEFINE_PRINT_STRING	
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS



Any help would be very much appreciated Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: 8086 assembler help

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5413
  • View blog
  • Posts: 27,429
  • Joined: 10-May 07

Re: 8086 assembler help

Posted 14 November 2009 - 10:52 PM

I would call the command cmp to compare the values, & then you can use any of the following :

jne (jump if not equal to)
jle (jump if less than or equal to)
jgt (jump if greater than or equal to)
Was This Post Helpful? 0
  • +
  • -

#3 FCW1073  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 14-November 09

Re: 8086 assembler help

Posted 14 November 2009 - 11:25 PM

Ok first off thank you i think i almost have it but im still getting it a bit messed up. If you would please tell me if i placed what you said in the right spot.

include 'emu8086.inc'
org  100h; set location counter to 100h
jmp CodeStart
DataStart:
	promptMsg db "enter a number> ", 0
	minMsg db "the smallest number is ", 0
	newline db 13, 10, 0
	num1 dw ?
	num2 dw ?
CodeStart:
	
  ; prompt user to enter in a number
	mov si, offset promptMsg
	call print_string
	
  ; read in the number into cx
	call scan_num
	
  ; move the number to a variable
	mov num1, cx
	
  ; advance cursor to the next line
	mov si, offset newline
	call print_string
  ; prompt user to enter in a number
	mov si, offset promptMsg
	call print_string
	
  ; read in the number into cx
	call scan_num
	
  ; move the number to a variable
	mov num2, cx
	
  ; advance cursor to the next line
	mov si, offset newline
	call print_string
  ; print min message
	mov si, offset minMsg
	call print_string
	mov ax, num1
	
	cmp num1,ax
	cmp num2,cx,jle,ax
	call print_num	
	
	EndLabel:
	ret
	
DEFINE_PRINT_STRING	
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS


This post has been edited by FCW1073: 14 November 2009 - 11:26 PM

Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5413
  • View blog
  • Posts: 27,429
  • Joined: 10-May 07

Re: 8086 assembler help

Posted 14 November 2009 - 11:30 PM

Quote

	cmp num1,ax
	cmp num2,cx,jle,ax


1st, cmp can only take two arguments :)

I would just compare num1 to num2 & jump based on the result.
Was This Post Helpful? 0
  • +
  • -

#5 FCW1073  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 14-November 09

Re: 8086 assembler help

Posted 15 November 2009 - 12:11 AM

Well after doing what you said it does the same but i am wondering where would or maybe i dont not sure where to put the result



org  100h; set location counter to 100h
jmp CodeStart
DataStart:
	promptMsg db "enter a number> ", 0
	minMsg db "the smallest number is ", 0
	newline db 13, 10, 0
	num1 dw ?
	num2 dw ?
CodeStart:
	
   ; prompt user to enter in a number
	mov si, offset promptMsg
	call print_string
	
   ; read in the number into cx
	call scan_num
	
   ; move the number to a variable
	mov num1, cx
	
   ; advance cursor to the next line
	mov si, offset newline
	call print_string
   ; prompt user to enter in a number
	mov si, offset promptMsg
	call print_string
	
   ; read in the number into cx
	call scan_num
	
   ; move the number to a variable
	mov num2, cx
	
   ; advance cursor to the next line
	mov si, offset newline
	call print_string
   ; print min message
	mov si, offset minMsg
	call print_string
	mov ax, num1
	
	cmp num1,ax,
	cmp num2,cx,jle,ax,
	call print_num	
	
	EndLabel:
	ret
	
DEFINE_PRINT_STRING	
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1