Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8384965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:32:49+00:00 2026-06-09T17:32:49+00:00

.text .align 2 .global main .equ val,0x4712 # 16-bit binary code for 0x4712: 0100

  • 0
    .text
    .align 2
    .global main
    .equ val,0x4712         # 16-bit binary code for 0x4712: 0100 0111 0001 0010
                            # Program code starts now
main:                          
        movi r16,val
        movi r17,0
loop:   addi r17,r17,1
        subi r16,r16,1 
        bne  r16,r0,loop
stop:   br   stop

How should I do to translate the above to machine code? I need to know how to make the translation besides the actual code. I figure I could try and get the opcodes for the instructions but the movi is a pseudoinstruction and I don’t know where I can get it. Should I read it in the Nios II manual?

Update

The first four instructions are type immediate so that field form should be used. movi and subi both are pseudoinstruktions implemented in addi so the opcode for addi will be used. I was helped and I know that the instruction movi r16, val will translate to

00000100000100011100010010000100

so the opcode is 000100 binary which is 0x04 in hex base which the manual also states is the opcode for addi. So I think we have the first four opcodes, they are all 000100.

Update 2

I think I know the opcode and the immediate field of most of the instructions now:

The sequence 0100011100010010 is 0x4712 which is the variable val that was declared with .equ,
So the first four opcodes should be 000100 since they’re all addi and addi says it’s 0x04. How to translate the two five-bit fields for the registers I don’t know right now but could be checking with the manual. It says ‘brhas opcode 0x06 so it should say 000110 in the opcode for br.bne` has opkod 0x1E which binary is 011110 = 30 (?)

Is this a correct beginning?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:32:51+00:00Added an answer on June 9, 2026 at 5:32 pm

    First off, why dont you at least try using an assembler to see what is produced?

    You need to read the mips instruction set references to see the real mips instructions, often the pseudo instructions are described in these references. as far as movi goes, load upper is a bit obvious for controlling the upper bits, and either and or or or is an obvious way to set the lower bits. If the value is a small number then you only need and or or and use r0 as one of the operands (to zero the upper bits).

    The problem with these pseudo instructions in mips is that you have to be careful not to use one in a branch shadow (unless it translates to a single instruction). I recommend learning an assembly language first using none of the pseudo instructions, then later to make your life easier, once you understand the instruction set and rules, then use pseudo instructions to make the code more readable or maintainable, etc. Personally I tend to stay with the pure instructions, giving a one-to-one experience (asm instruction to machine instruction).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example: .text .align 2 .global main .equ val,0x4712 # 16-bit binary code for
.global main # makes label main globally known .text # Instructions follow .align 2
This is my code for my menu: /*Menu*/ #menu { text-align: right; margin-left: auto;
I am using text-align:justify to evenly space out inline-block elements. I am using jQuery
Is there any way to make the text align left and justify as same
1) If inside CSS file we specify the following style: td { text-align:center; }
I have the following CSS and HTML: .TestPadding{ width:29px; text-align:center; height:18px; padding:3px 0px 2px
I saw this selector in Twitter Bootstrap: .show-grid [class*=span] { background-color: #eee; text-align: center;
<html> <head></head> <body> <div id=ctl00_ContentPlaceHolder1_ctl00_ctl01_Showcase> <div style=width:100%;text-align:center;><img src=http://www.xyz.com/aaa.gif id=ctl00_ContentPlaceHolder1_ctl00_ctl01_loderImg alt=Loading /></div> </div> <script> q=
Given this simplified snippet : <html> <body> <div> <div style='text-align:center;'>asdfaskjdfakjsd</div> <div style='float:right'> <input type='submit'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.