The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

x86 Assembly help, one last time!

clsCorwinclsCorwin Registered User regular
edited April 2007 in Help / Advice Forum
Tried to tack this onto an old thread, but she got no love.

I'm running into some issues with a macro in my program.

lab8.asm
INCLUDE input
INCLUDE input2

.MODEL  SMALL

.STACK  100h

.DATA
	basePrompt	db	'Please enter a number for the base: $'
	expPrompt	db	'Please enter a number to raise the base to: $'
	base		db	?
	exp		db	?
	binBase		db	?
	binExp		db	?
	baseSize	db	?
	expSize		db	?
	answerSize	db	?
	answer		dw	1
	divider		db	10
	ASCIIanswer	dw	?
	cheat		db	'$'

.CODE
	EXTRN GETNUMBER:far, PUTNUMBER:far, POWER:far

MAIN PROC
	mov	ax, @data
	mov	ds, ax
	
	lea	dx, basePrompt
	mov	ah, 09h
	int	21h			;display prompt	
	INPUT	base			;get base number
	
	lea	dx, expPrompt
	mov	ah, 09h
	int	21h			;display prompt
	INPUT2	exp			;get exponent
	
	call	GETNUMBER		;convert numbers to binary
	
	mov	ax, 0
	mov	al, binBase
	call	GETSIZE			;get number of digits in base
	;mov	baseSize, bl		;set base size
		
	mov	ax, 0
	mov	al, binExp
	call	GETSIZE			;get number of digits in exp
	;mov	expSize, bx		;set exp size	
	
	call	POWER			;raise base to exp power
	
	mov	ax, answer
	call	GETSIZE			;get number of digits in answer
	mov	bx, 0
	mov	answerSize, bl		;set answer size
	
	call	PUTNUMBER		;convert answer to ascii for printing
	call	PRINT			;print answer
	
	mov	ax, 4c00h
	int	21h			;terminate program
	
MAIN ENDP

GETSIZE PROC
	cmp	ax, 10000		;compare num to 10000
	jb	NOT5			;if smaller, jump to NOT5
	mov	bx, 5			;else size = 5

	NOT5:
	cmp	ax, 1000		;compare num to 1000
	jb	NOT4			;if smaller, jump to NOT4
	mov	bx, 4			;else size = 4

	NOT4:
	cmp	ax, 100			;compare num to 100
	jb	NOT3			;if smaller, jump to NOT3
	mov	bx, 3			;else size = 3

	NOT3:
	cmp	ax, 10			;compare num to 10
	jb	CONTINUE1		;if smaller, size = 1
	mov	bx, 2			;else size = 2
	
	CONTINUE1:
	mov	bx, 1			;size = 1
	
	ret
GETSIZE ENDP

PRINT PROC
	mov	ax, ASCIIanswer
	mov	ah, 09h
	int	21h			;print answer

PRINT ENDP

END MAIN

input
INPUT MACRO addr
	lea	bx, addr		;load addr into bx
	mov	cx, 2			;set counter to 2
	mov	si, 0			;set pointer to 0
	
INLOOP:
	mov	ah, 01h
	int	21h			;get char from keyboard
	mov	bx + si, al		;put char into bx
	inc	si
	loop	INLOOP
	
ENDM

This is the output I get upon trying to assemble lab8.asm:

Turbo Assembler Version 4.1 Copyright (c) 1988, 1996 Borland International

Assembling file: lab8.asm
**Error** lab8.asm(61) INPUT(8) Too many registers in expression
**Error** lab8.asm(66) INPUT2(8) Too many registers in expression
Error messages: 2
Warning messages: None
Passes: 1
Remaining memory: 413k


Tool completed with exit code 1

Mind you, this is 16 bit assembly for x86. Why is it complaining about the macro?

clsCorwin on

Posts

  • BamaBama Registered User regular
    edited April 2007
    I looks like you're trying to put the sum of two registers in another register with a mov instruction. Shouldn't you be using an add? I can't think of an instance where an expression is a valid instruction parameter.

    Bama on
  • SmasherSmasher Starting to get dizzy Registered User regular
    edited April 2007
    I have no experience with x86 assembly, but I'll give this a stab. Take with a grain of salt.

    It looks like it's complaining about one of these two lines, depending how it counts line numbers in macros:

    int 21h
    mov bx + si, al

    The int seems to look fine, so my hunch is that you're not allowed to add bx and si together like that. I don't know if that's actually true, but I notice you don't do it anywhere else in the code there. Try summing them in an extra register first (if you have a free one) and using that in the mov statement instead.

    Smasher on
  • clsCorwinclsCorwin Registered User regular
    edited April 2007
    Yep, I'm a jackass.

    clsCorwin on
  • FristleFristle Registered User regular
    edited April 2007
    mov        bx + si, al                ;put char into bx
    

    Yea that looks invalid.

    If you need to put AL into the address [BX plus an offset of SI] then you will have to store that address in another register first, then do a mov of AL to that address.

    Edit: beat to the punch!

    Fristle on
    Fristle.jpg
  • ecco the dolphinecco the dolphin Registered User regular
    edited April 2007
    mov [bx + si], al

    Is what you want.

    Ha, sorry about the other thread - absolutely forgot about it last night.

    EDIT: Woah, lots of answers all of a sudden. Anyway, no need to have another register - you can directly add si to bx in this context.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
Sign In or Register to comment.