16 Replies - 1440 Views - Last Post: 23 June 2012 - 11:16 AM
#1
Should I continue with MIPS?
Posted 19 June 2012 - 08:13 PM
Thanks!
Replies To: Should I continue with MIPS?
#2
Re: Should I continue with MIPS?
Posted 19 June 2012 - 08:19 PM
MIPS, ARM, x86 all have their place. If you want to reach a larger group of people, learn x86
#3
Re: Should I continue with MIPS?
Posted 20 June 2012 - 06:43 PM
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
#4
Re: Should I continue with MIPS?
Posted 20 June 2012 - 06:59 PM
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.
#5
Re: Should I continue with MIPS?
Posted 20 June 2012 - 07:07 PM
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
#6
Re: Should I continue with MIPS?
Posted 20 June 2012 - 07:17 PM
I fired up both 32 and 64bit linux, Assembled and linked no problems.
Quote
Sounds like you are using 64bit registers/instructions but Assembling/linking as 32bit
#7
Re: Should I continue with MIPS?
Posted 20 June 2012 - 07:27 PM
http://en.wikipedia....-bit_mode_Linux
compiled it as
nasm -f elf test.asm
Then I get that error for every line.
#8
Re: Should I continue with MIPS?
Posted 20 June 2012 - 07:29 PM
Quote
#9
Re: Should I continue with MIPS?
Posted 20 June 2012 - 07:39 PM

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...
#10
Re: Should I continue with MIPS?
Posted 20 June 2012 - 07:46 PM
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.
#11
Re: Should I continue with MIPS?
Posted 22 June 2012 - 08:18 PM
This post has been edited by carnivroar: 22 June 2012 - 08:18 PM
#12
Re: Should I continue with MIPS?
Posted 22 June 2012 - 08:26 PM
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
#13
Re: Should I continue with MIPS?
Posted 22 June 2012 - 08:45 PM
GunnerInc, on 22 June 2012 - 08:26 PM, said:
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
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"
#14
Re: Should I continue with MIPS?
Posted 22 June 2012 - 08:50 PM
#15
Re: Should I continue with MIPS?
Posted 22 June 2012 - 09:04 PM
GunnerInc, on 22 June 2012 - 08:50 PM, said:
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
|
|

New Topic/Question
Reply


MultiQuote






|