1 Replies - 2464 Views - Last Post: 15 September 2013 - 08:10 PM

#1 jeaninem71  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-September 13

Assembly language, need to use push and pop to write integers

Posted 15 September 2013 - 02:15 PM

I have my program working except to push and pop the integers entered by the user and write them in reverse in hex, binary and decimal. It is adding the integers up as needed, but I don't know how to get these numbers on the stack and then pop them to be able to write to the screen. I hope someone can tell me what I am doing wrong.

TITLE Numfun	 (numfun.asm)
; Program Description:
; Author:
; Date Created:
; Last Modification Date:

INCLUDE Irvine32.inc

TAB = 9	 ; ASCII code for Tab

.data

COUNT	DWORD ?
prompt1 BYTE "How many integers would you like to enter? ",0
prompt2 BYTE "Please enter an integer: ",0
str1	BYTE "The sum of the integers is: ",0
str2	BYTE "Display section - Loop 2",0

.code
main PROC

	mov		EAX,0
	mov		EBX,0
	mov		ECX,0
	mov		EDX,0

	call	Prompt
	call	Display

exit
main ENDP

;---------------------------------------------------------
Prompt PROC USES EAX
; Prompts user to input the number of integers they would 
; like to use, then asks user for each of the numbers.
; Receives: prompt1
; Returns: COUNT, 
;---------------------------------------------------------

	mov		edx,OFFSET prompt1		; ask user for input
	call	WriteString
	call	ReadInt					; read character into EAX
	mov		COUNT,EAX				; input integer into COUNT
	mov		ECX,COUNT				; move integer into ECX

L1:
	mov		edx,OFFSET prompt2
	call	WriteString
	call	ReadInt
	add		EBX,EAX
	mov		EDI,EAX
	call	Crlf					; new line
	call	DumpRegs
	call	Crlf					; new line
	loop	L1

	ret
	Prompt ENDP


;---------------------------------------------------------
Display PROC USES EAX ECX
;---------------------------------------------------------
; Display the integer in decimal, hexadecimal, and binary

mov		edx,OFFSET str2		; shows where display section starts, remove later
	call	WriteString
	call	Crlf					; new line
	mov			ECX,COUNT

L2:
	mov			EAX,EDI
	call		WriteHex			; display in hexadecimal
	mov			ESI,TAB
	call		WriteChar			; write the tab
	call		WriteBin			; display in binary
	mov			ESI,TAB
	call		WriteChar			; write the tab
	call		WriteInt			; display in signed decimal
	call Crlf						; new line
	loop		L2					; repeat the loop

	mov		edx,OFFSET str1			; Sum of integers
	call	WriteString
	mov		EAX,EBX
	call    WriteInt
	call	Crlf					; new line

	call	DumpRegs

	ret
	Display ENDP

END main



Is This A Good Question/Topic? 0
  • +

Replies To: Assembly language, need to use push and pop to write integers

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,281
  • Joined: 28-March 11

Re: Assembly language, need to use push and pop to write integers

Posted 15 September 2013 - 08:10 PM

I will take a guess and say this is the output you are expecting?

Attached Image

So, where would you push the entered numbers onto the stack, and where would you pop the numbers off of the stack to print them?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1