Welcome to E8 :: [eon8]

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll also be able to use the shoutbox, customize your profile, change themes, gain reputation points for submitting content, while also communicating with other members via your own private messenger, plus much more!

 

This message will be removed once you have signed in.

Sign in to follow this  
kxrxoxnxixc

Machine Language/assembly language

9 posts in this topic

Anybody know any beginner machine language? Or know of any good books to get or search for to teach myself some machine language?

Share this post


Link to post
Share on other sites

_start:	

; initializes the two numbers and the counter.  Note that this assumes

; that num1 and num2 areas are contiguous!

;

	mov	eax,'0000'	; initialize to all ASCII zeroes

	mov	edi,num1	; 

	mov	ecx,1+digits/2; four bytes at a time and one extra

	cld		; initialize from low to high memory

	rep	stosd	; write the data

	inc	eax	; make sure ASCII zero is in al

	mov	[num2 + digits - 1],al; last digit is one

	mov	[counter + cntDigits - 1],al; 

	mov	dword [msg2],middle


	mov	ebp,[msd2]

	jmp	.bottom	; done with initialization, so begin


.top

; add num2 to num1

	mov	edi,num1+digits-1

	mov	esi,num2+digits-1

	mov	ecx,digits; 

	mov	ebp,[msd1];

	call	AddNumbers; num1 += num2

	mov	[msd1],ebp;

	inc	ebp

	mov	ebx,num1+digits

	sub	ebx,ebp	; get length in ebx

	call	PrintLine;

	dec	dword [term]; decrement loop counter

	jz	.done	;


; add num1 to num2

	mov	edi,num2+digits-1

	mov	esi,num1+digits-1

	mov	ecx,digits;

	mov	ebp,[msd2];

	call	AddNumbers; num2 += num1

	mov	[msd2],ebp;

	inc	ebp

.bottom

	mov	ebx,num2+digits

	sub	ebx,ebp	; get length in ebx

	call	PrintLine;

	dec	dword [term]; decrement loop counter

	jnz	.top	;

.done

	call	CRLF	; finish off with CRLF

	mov	ebx,0	; exit code

	mov	eax,1h	; sys_exit

	int	80h	;


;****************************************************************************

;

; PrintLine

; prints a single line of output containing one term of the 

; Fibonacci sequence.  The first few lines look like this:

;

; Fibonacci(1): 1

; Fibonacci(2): 1

; Fibonacci(3): 2

; Fibonacci(4): 3

;

; INPUT:	 ds:ebp ==> number string, ebx = string length

; OUTPUT:	CF set on error, EAX = error code if carry set

; DESTROYED: eax, ecx, edx, edi

;

;****************************************************************************

PrintLine:

	push	ebx

	mov	ecx,eol	; print combined CRLF and msg1

	mov	edx,msg1len+eollen  ; 

	call	PrintString;


	mov	edi,counter; print counter and msg2

	mov	ecx,cntDigits + msg2len;

	call	PrintNumericString


	call	IncrementCount; also increment the counter


	mov	ecx,ebp	; get pointer to number string

	pop	edx	; and length of it

	jmp	PrintString;


;****************************************************************************

;

; PrintNumericString 

; prints the numeric string at DS:EDI, suppressing leading zeroes

; max length is ECX

;

; INPUT:	 ds:edi ==> number string, ecx = max string length

; OUTPUT:	CF set on error, EAX = error code if carry set

; DESTROYED: eax, ecx, edx, edi

;

;****************************************************************************

PrintNumericString:

; first scan for the first non-zero byte

	mov	al,'0'	; look for ASCII zero

	cld		; scan from MSD to LSD

	repe	scasb	;

	mov	edx,ecx	;

	mov	ecx,edi	; points to one byte after

	dec	ecx	; back up one character

	inc	edx	;

; deliberately fall through to PrintString


;****************************************************************************

; 

; PrintString 

; prints the string at ECX with length EDX to stdout

;

; INPUT:	 ds:ecx ==> string, edx = string length

; OUTPUT:	CF set on error, EAX = error code if carry set

; DESTROYED: eax

;

;****************************************************************************

PrintString:

	mov	ebx, 1	; write to stdout

	mov	 eax, 4h		; write to file handle

	int	80h	; ignore return value

	ret		;


;****************************************************************************

;

; AddNumbers

; add number 2 at ds:esi to number 1 at es:edi of width ecx

; 

;

; INPUT:	 es:edi ==> number1, ds:esi ==> number2, ecx= max width

;		ds:ebp ==> msd of number 1

; OUTPUT:	CF set on overflow

; DESTROYED: eax, esi, edi

;

;****************************************************************************

AddNumbers:

	dec	ebp	; 

	std		; go from LSB to MSB

	clc		;

	pushf		; save carry flag

.top

	mov	eax,0f0fh; convert from ASCII BCD to BCD

	and	  al,[esi]; get next digit of number2 in al

	and	ah,[edi]; get next digit of number1 in ah

	popf		; recall carry flag

	adc	al,ah	; add these digits

	aaa		; convert to BCD

	pushf		;

	add	al,'0'	; convert back to ASCII BCD digit

	stosb		; save it and increment both counters

	dec	esi	;

;

	cmp	edi,ebp	; are we at a new significant digit?

	loopnz	.top	; keep going until we've got them all

	cmp	al,'0'	; is it a zero?

	jnz	.done	; yes, so keep 

	inc	ebp	;

.done

	popf		; recall carry flag

	ret		;


;****************************************************************************

; 

; IncrementCount

; increments a multidigit term counter by one

;

; INPUT:	 none

; OUTPUT:	CF set on overflow

; DESTROYED: eax, ecx, edi

;

;****************************************************************************

IncrementCount:

	mov	ecx,cntDigits;

	mov	edi,counter+cntDigits-1

	std		; go from LSB to MSB

	stc		; this is our increment

	pushf		; save carry flag

.top

	mov	ax,000fh; convert from ASCII BCD to BCD

	and	al,[edi]; get next digit of counter in al

	popf		; recall carry flag

	adc	al,ah	; add these digits

	aaa		; convert to BCD

	pushf		;

	add	al,'0'	; convert back to ASCII BCD digit

	stosb		; save and increment counter

	loop	.top	;

	popf		; recall carry flag

	ret		;


;****************************************************************************

;

; CRLF

; prints carriage return, line feed pair to stdout

;

; INPUT:	 none

; OUTPUT:	CF set on error, AX = error code if carry set

; DESTROYED: ax, bx, cx, dx

;

;****************************************************************************

CRLF:	mov	ecx,eol	;

	mov	edx,eollen;

	jmp	PrintString;


;****************************************************************************

; data

;****************************************************************************

section .data

eol	db  10		; Linux-style end of line

eollen	equ $ - eol


msg1	db  'Fibonacci(';

msg1len	equ $ - msg1

;****************************************************************************

term dd maxTerms	;

;****************************************************************************

counter times cntDigits db '0'


middle  equ '): '

msg2	dd  0;middle	;

msg2len	equ 3


msd1 dd num1+digits-1	; pointer to most significant digit of num1

msd2 dd num2+digits-1	; pointer to most significant digit of num2


num1 times digits db 0

num2 times digits db 0

overrun times 4 db 0	; extra space to assure we don't overwrite

Got this source code from: http://www.beroset.com/asm/fibo-linux.asm

Share this post


Link to post
Share on other sites

No not ASCII. Assembly language. It's a really low level of programming language, basically the closest you can get to 1's and 0's.

Share this post


Link to post
Share on other sites

I took programming classes in college like mentioned in that other thread but I couldn't get into it. That was also six years ago. Maybe I should check it out again.

Share this post


Link to post
Share on other sites

Yeah im taking c++ right now, and I have to eventually take assembly language and was gonna try and get a quick start on it by reading up on it and trying to use it to make some shit. I heard a simple "Hello World" program could take like 40 lines or more... > . >

Share this post


Link to post
Share on other sites

That was one of the main reasons I lost interest. The fact that you have to write lines and lines of code just to do nothing, and then of course if theres a single mistake it doesn't even work right. llsweatdrop.gif

Share this post


Link to post
Share on other sites

Yeah I think im gonna take some Linux or UNIX and networking courses over the summer next semester, not this coming one, but the next one. See if I don't like networking better. IDK, I know I don't wanna be a programmer though, even though you learn some really cool shit.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this