Should I continue with MIPS?

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 2115 Views - Last Post: 23 June 2012 - 11:16 AM

#1 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

Should I continue with MIPS?

Posted 19 June 2012 - 08:13 PM

I love assembly language and I want to continue learning it. I studied MIPS in my computer organization course and I was really good at it. However it doesn't seem like a very useful architecture to know. Should I continue programming with it or should I move on to something like x86?

Thanks!
Is This A Good Question/Topic? 0
  • +

Replies To: Should I continue with MIPS?

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




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

Re: Should I continue with MIPS?

Posted 19 June 2012 - 08:19 PM

Moving to Assembly

MIPS, ARM, x86 all have their place. If you want to reach a larger group of people, learn x86
Was This Post Helpful? 0
  • +
  • -

#3 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

Re: Should I continue with MIPS?

Posted 20 June 2012 - 06:43 PM

Okay. Sorry for my ignorance, I'm not much of a hardware person.

Which language is this?

;
; This program runs in 32-bit protected mode.
;  build: nasm -f elf -F stabs name.asm
;  link:  ld -o name name.o
;
; In 64-bit protected mode you can use 64-bit registers (e.g. rax instead of eax, rbx instead of ebx, etc..)
; Also change "-f elf " for "-f elf64" in build command.
;
section .data                           ; section for initialized data
str:     db 'Hello world!', 0Ah         ; message string with new-line char at the end (10 decimal)
str_len: equ $ - str                    ; calcs length of string (bytes) by subtracting this' address ($ symbol) from the str's start address
 
section .text                           ; this is the code section
global _start                           ; _start is the entry point and needs global scope to be 'seen' by the linker -equivalent to main() in C/C++
_start:                                 ; procedure start
        mov     eax, 4                   ; specify the sys_write function code (from OS vector table)
        mov     ebx, 1                   ; specify file descriptor stdout -in linux, everything's treated as a file, even hardware devices
        mov     ecx, str                 ; move start _address_ of string message to ecx register
        mov     edx, str_len             ; move length of message (in bytes)
        int     80h                      ; tell kernel to perform the system call we just set up - in linux services are requested through the kernel
        mov     eax, 1                   ; specify sys_exit function code (from OS vector table)
        mov     ebx, 0                   ; specify return code for OS (0 = everything's fine)
        int     80h                      ; tell kernel to perform system call



I got it from Wikipedia to test. I'm using Nasm to compile it and run on linux. For some reason I can't run the 64 bit version, but this one works.

Also, according to a tutorial I found, I'm supposed to input this but I get:

ld test.o -o test
ld: i386 architecture of input file `test.o' is incompatible with i386:x86-64 output

However, this works:

ld -m elf_i386 -s test.o -o test

Can anyone clarify what's happening? I have a core i5 processor.

Thank you and once again, anything beyond MIPS is new to me.

This post has been edited by carnivroar: 20 June 2012 - 06:43 PM

Was This Post Helpful? 0
  • +
  • -

#4 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




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

Re: Should I continue with MIPS?

Posted 20 June 2012 - 06:59 PM

Your using a PC right? Then it is x86.

You cannot use 64bit code on a 32bit processor/OS. If your processor is 64bit, then install the 64bit version of Linux to use 64bit code.
Was This Post Helpful? 0
  • +
  • -

#5 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

Re: Should I continue with MIPS?

Posted 20 June 2012 - 07:07 PM

Hmm I do have the 64 bit Linux:

Release 12.04 (precise) 64-bit

And core i5 is 64 bit, right? I just got Linux for the first time a few days ago.

This is the error I'm getting when I try to compile a 64 bit code:

test.asm:8: error: instruction not supported in 32-bit mode
Was This Post Helpful? 0
  • +
  • -

#6 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




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

Re: Should I continue with MIPS?

Posted 20 June 2012 - 07:17 PM

What is line 8? The code you posted, line 8 is a comment.

I fired up both 32 and 64bit linux, Assembled and linked no problems.

Quote

test.asm:8: error: instruction not supported in 32-bit mode

Sounds like you are using 64bit registers/instructions but Assembling/linking as 32bit
Was This Post Helpful? 0
  • +
  • -

#7 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

Re: Should I continue with MIPS?

Posted 20 June 2012 - 07:27 PM

It's this program

http://en.wikipedia....-bit_mode_Linux

compiled it as

nasm -f elf test.asm

Then I get that error for every line.
Was This Post Helpful? 0
  • +
  • -

#8 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




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

Re: Should I continue with MIPS?

Posted 20 June 2012 - 07:29 PM

Well, doesn't it say for 64bit use:

Quote

Also change "-f elf " for "-f elf64" in build command

Was This Post Helpful? 0
  • +
  • -

#9 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




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

Re: Should I continue with MIPS?

Posted 20 June 2012 - 07:39 PM

You really can't learn from wiki, you need to get a book, or a tutorial for Linux Assembly.
Attached Image

The 64bit code Assembled as 32 bit won't work, but as 64bit it is fine. 32bit does not have the 64bit registers rax, rcx, rdx, etx...
Was This Post Helpful? 0
  • +
  • -

#10 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

Re: Should I continue with MIPS?

Posted 20 June 2012 - 07:46 PM

Ooops, I missed that line. I was following another tutorial...

So I did exactly what you did and it works as expected.

Should I get this book? http://www.amazon.co...r/dp/0764579010

Thanks a lot.
Was This Post Helpful? 0
  • +
  • -

#11 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

Re: Should I continue with MIPS?

Posted 22 June 2012 - 08:18 PM

Since I'm only learning assembly for fun I decided to stick with MIPS (I also found a great cheap book on RISC architecture that I could pick up from where I left). Is there a way to compile MIPS code the way we just did with x86? I don't really like using MARS.

This post has been edited by carnivroar: 22 June 2012 - 08:18 PM

Was This Post Helpful? 0
  • +
  • -

#12 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




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

Re: Should I continue with MIPS?

Posted 22 June 2012 - 08:26 PM

Unless you have a RISC chip, then you cannot just run your MIPS exe. You need to use an emulator/simulator.

Why not learn x86? It is not much different, all PCs are CISC so your program will run without an emulator. You can be productive with x86, meaning folks can use/buy your program.

Oh, and in Assembly we NEVER compile!!! We Assemble and/or link :P
Was This Post Helpful? 0
  • +
  • -

#13 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

Re: Should I continue with MIPS?

Posted 22 June 2012 - 08:45 PM

View PostGunnerInc, on 22 June 2012 - 08:26 PM, said:

Unless you have a RISC chip, then you cannot just run your MIPS exe. You need to use an emulator/simulator.

Why not learn x86? It is not much different, all PCs are CISC so your program will run without an emulator. You can be productive with x86, meaning folks can use/buy your program.

Oh, and in Assembly we NEVER compile!!! We Assemble and/or link :P


Is the book I mentioned above a good place to start? I just want to do some project euler problems in assembly for fun and to build up my portfolio. I like the idea of being able to execute the code in its full potential instead of using an emulator. For my computer organization course we did one of those problems as an extra credit. To give you an idea, this is as far as I can program in assembly:

#FIND THE 10001ST PRIME

# $s0 = N (starts at 3)
# $t0 = counts up to 10001, starts at 1
# $t1 = counts up to N, starts at 3, ends at square root approximation
# $t2 = value of division
# $t3 = remainder 
# $t4 = square root approximation

INIT:

addi	$t0, $zero, 1		# initiates $t0 to 1
addi	$s0, $zero, 1		# initiates $s0 to 1
addi	$t4, $zero, 1		# square root approximation
addi	$a0, $zero, 2	  	# prints first prime which is 2
li		$v0, 1           	# print integer instruction
syscall						# prints

NEXT:

beq		$t0, 10001, DONE	# done if it's the 10001st prime
addiu	$s0, $s0, 2			# else increment N by 2
addi	$t1, $zero, 3		# reset $t1 to 3

SQRT:

mulu	$t5, $t4, $t4		# multiply "square root" candidate by itself
sgt		$t6, $t5, $s0		# test if the result of the multiplication is greater than N
bnez  	$t6, PRIMETEST		# if it is, it's a good enough approximation
addi	$t4, $t4, 1			# else increment "square root"
j		SQRT				# do it again

PRIMETEST:

bgt 	$t1, $t4, ISPRIME	# if it bypassed all the following checks, then it's a prime
div		$t2, $s0, $t1		# divide $s0 by $t1
mfhi	$t3					# stores remainder of previous operation on $t2
beqz	$t3, NEXT			# if remainder is 0 => evenly divided => not a prime
add		$t1, $t1, 2			# increments $t1 by 2
j		PRIMETEST			# go back

ISPRIME:
    
addi	$t0, $t0, 1			# increment prime count
la		$a0, nl				# load new line character into $a0
li		$v0, 4         	 	# print string instruction
syscall						# prints
add 	$a0, $s0, $zero		# load prime value $s0 into $a0
li		$v0, 1           	# print integer instruction
syscall						# prints
j		NEXT				# try new number

DONE:
							# do nothing, we're done

.data				
nl: .asciiz "\n"


Was This Post Helpful? 0
  • +
  • -

#14 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




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

Re: Should I continue with MIPS?

Posted 22 June 2012 - 08:50 PM

Personally I would not get the book. Why? It uses the god awful AT&T syntax instead of the INTEL syntax which is much cleaner looking. More info here But you might be right at home with it.
Was This Post Helpful? 0
  • +
  • -

#15 carnivroar  Icon User is offline

  • D.I.C Regular

Reputation: 28
  • View blog
  • Posts: 382
  • Joined: 18-September 11

Re: Should I continue with MIPS?

Posted 22 June 2012 - 09:04 PM

View PostGunnerInc, on 22 June 2012 - 08:50 PM, said:

Personally I would not get the book. Why? It uses the god awful AT&T syntax instead of the INTEL syntax which is much cleaner looking. More info here But you might be right at home with it.


Okay. I downloaded the Intel® 64 and IA-32 Architectures Software Developer’s Manual. I was looking for something more like a textbook instead but this seems like the most standard source to learn from, so I'll look into it.

This post has been edited by carnivroar: 22 June 2012 - 09:04 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2