1 Replies - 8182 Views - Last Post: 19 February 2010 - 02:38 AM

#1 nelly101  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-February 10

ASSEMBLY LANGUAGE ADDITION

Posted 19 February 2010 - 02:34 AM

MY PROBLEM IS... I DONT KNOW HOW TO INPUT TWO DIGITS..AND WHERE WILL i put them for them not to be overwritten..please help me...

mov dx, offset string1
call display



call firstNum
call Compare	



mov ah,2
mov dx, 0Ah
int 21h

mov dx, offset string2
call display


call firstNum
call Compare


mov ah,2
mov dx, 0Ah
int 21h

mov dx, offset sum
call display
mov dl, bl

call GetNum

int 20h


string1 db 'Input first number[0-99]: $'
string2 db 'Input first number[0-99]: $'
sum db 'SUM: $'

;START display1
display:
	mov ah, 9
	int 21h
	ret
;END


firstNum:
	input:
		push ax
		mov ah, 0
		int 16h	
		
		pop ax
		call GetNum	
		ret

GetNum:
	mov ah, 2
	mov dl, bl
	int 21h

; END GETNUM


Compare:
		
		cmp dl, 0Dh
		
		jne TRUE
		je FALSE
		
		TRUE:
			call firstnum
			
		FALSE:

ret


This post has been edited by no2pencil: 19 February 2010 - 02:37 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: ASSEMBLY LANGUAGE ADDITION

#2 no2pencil  Icon User is offline

  • Dic Head
  • member icon

Reputation: 5167
  • View blog
  • Posts: 26,850
  • Joined: 10-May 07

Re: ASSEMBLY LANGUAGE ADDITION

Posted 19 February 2010 - 02:38 AM

** Moved to assembly **

You can use the following to read from stdin.

; nasm -f elf -o input.o input.asm
; ld -s -o input input.o
section .data
var:  DB 0                      ; declare var with value 0
don:  DB 10             ; declare our done value at 10
msg:  DB "Please enter your name: "
len:  equ $-msg ; the length of msg
dic:  DB "Welcome to Dream In Code, "
dic_ln: equ $-dic
buffer: DB "                                    "; input buffer = 20 bytes
bf_sz: equ $-buffer

section .text
global _start

_start:
  mov eax, 4; pass sys_write
  mov ebx, 1; stdout
  mov ecx, msg; Load register ecx with prompt msg
  mov edx, len; Load register edx with length of msg
  int 0x80      ; return to the kernel
  jmp stdin  ; Go to input function

stdout:
   mov eax, 4; pass sys_write
   mov ebx, 1; stdout
   mov ecx, dic
   mov edx, dic_ln
   int 0x80; return to the kernel

   mov eax, 4; pass sys_write
   mov ebx, 1; stdout
   mov ecx, buffer; display the buffer contents
   mov edx, bf_sz; size of buffer
   int 0x80      ; return to the kernel
   jmp end       ; We are all finished

stdin:
; Get text from keyboard buffer
  mov eax, 3; pass sys_read
  xor ebx, 0; stdin
  mov ecx, buffer
  mov edx, bf_sz; count
  int 0x80      ; return

  jmp stdout; Go to display function

end:
  ret


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1