MIPS Printing a Label - printing

I am now starting to use Mars to code In Assembly, I wrote the following code but got an error. Any ideas why?
.text
main:
la $ao,Pat
li $sv0,4
syscall
li $vo,10
syscall
.data
Pat:.asciiz "My name is Patricia"
Can also someone explains if there are some specific things to write before ".text" or after ".data".

.text
main:
la $a0,Pat
li $v0,4
syscall
li $v0,10
syscall
.data
Pat:.asciiz "My name is Patricia"
First of all v0 is the main thing which tells the assembler what to print. Since you are printing integers, v0 needs to be 1. The same goes for the others like:
float : 2
double : 3
word , string : 4
After giving the instruction, you can print by putting value only in a0 (its reserved for that).
So now the code will give you the result:
Code run result
Earlier in your code, sv0 was written and in some places instead of 0. :)

Related

Why does Delphi 7 truncate file after ASCII code 14 when opening in Append mode?

I'm working on some legacy software written in Delphi 7 which runs on Windows. I've minified the problem to the following program:
var f: text;
begin
assign(f, 'a.txt');
rewrite(f);
writeln(f, 'before' + chr(14) + 'after');
close(f);
assign(f, 'a.txt');
append(f);
close(f);
end.
I expect it to create a.txt file containing "before#14after#13#10" and then append nothing to it. However, after I run this program on Windows, I see before in a.txt instead, like if Delphi's append truncates the file. If I do not re-open the file, it shows before#14after#13#10 as expected.
If I write something (FooBar) in the re-opened file, it's appended, but as if the file was already truncated: beforeFooBar.
This effect does not occur with any other character between 0 and 32, even with 26 (which stands for EOF).
Is this a bug in Delphi or a well-defined behavior? What is so special about chr(14)?
Thanks to some friends from a chat and Sertac Akyuz from comments: it looks like a bug in Delphi 7.
It's supposed to have special handling of the EOF symbol (ASCII 26), quoting from here:
Note: If a Ctrl+Z (ASCII 26) is present in the last 128-byte block of the file, the current file position is set so that the next character added to the file overwrites the first Ctrl+Z in the block. In this way, text can be appended to a file that terminates with a Ctrl+Z.
Kind of CP/M backward compatibility, I guess.
However, there is a bug in the implementation of TextOpen for Windows (see Source/Rtl/Sys/System.pas from your Delphi 7 installation around line 4282):
##loop:
CMP EAX,EDX
JAE ##success
// if (f.Buffer[i] == eof)
CMP byte ptr [ESI].TTextRec.Buffer[EAX],eof
JE ##truncate
INC EAX
JMP ##loop
Here it says eof instead of cEof. Unfortunatley, that compiles for some reason and it even appeared on StackOverflow already. There is a label called ##eof and that's pretty much it.
Consequence: instead of having special case for 26, we have special case for 14. The exact reason is yet to be found.

print in MIPS the corresponding HI and LO number

does someone know how to print HI and LO correctly when you make the multiplication in MIPS?. The HI and LO works as 64bits register, but the read print syscall only works with 32 bits. I need create a code to print the correponding HI LO number.

Mips assembly Calculator Equation Parse

I am making a mips assembly language type of calculator. It gets an equation as the data and I have to parse the equation and follow PEMDAS (order of operations). I can not seem to figure out how to parse and store the string in order for me to do this. I understand that you have to check the hex value of the equation to know what mathematical problem to solve, but don't know how to code it. Also after we multiply two numbers how do you put the answer back into the equation to continue iterating through it. Some code is below, that I worked up, that needs accomplish this. This equation is just an example. Parentheses and exponents aren't used in this. Since this is assembly I didn't put my exact code in as that would be tons of lines but I drew an outline and what I needs fixing or help on and what I have and understand. If i can understand the parse and how the equation and numbers are stored I can probably fix the rest myself so really I just need help at the parse and pemdasone, two, and three labels.
.globl division
.globl multiplication
.globl addition
.globl subtraction
.globl end
.globl PemdasOne
.globl PemdasTwo
.globl PemdasThree
.globl parse
.data
a: .half 2
b: .half 3
c: .half 8
d: .half 35
exp: .asciiz "b:=26/a-c+b"
.text
parse:
(HELP!This is the part that needs work.) (HELP! Read and store expression)
(HELP! Create iterator to keep spot in the equation?)
pemdasone:
(HELP! Check if ascii value at iterator is * or /)
(UNDERSTAND: if so branch or jump to math equation)
(UNDERSTAND: if not branch or jump to pemdastwo)
pemdastwo:
(HELP! check if ascii value at iterator is + or -, reiterate through equation with updated values after pemdasone is done with what it does)
(UNDERSTAND: if so branch or jump to math equation)
(UNDERSTAND: if not branch or jump to pemdasthree)
pemdasthree:
(HELP! check if equation is completed. Store answer in variable b so it is updated from the input value to the answervalue.)
(UNDERSTAND that if it is done jump to end label)
multiplication:
(HELP! get number before the ascii value of * and fter the ascii value of * and store them in registers for the equation.)
(UNDERSTAND: how to do the mathmatical operator with two numbers.)
(HELP! store answer in equation so you can keep doing the equation)
(UNDERSTAND: that jump or branch back to pemdasone)
division:
(All the math parts are the same help and understands just with new operator and jump and branch locations)
addition:
(Same help and understands as divide and multiply except jump to pemdastwo)
subtraction:
(Same as addition)
end:
(UNDERSTAND that you store the answer into the variable it tells you to)
(HELP! with memory and where we stored the answer)

parsing input file in fortran

This is a continuation of my older thread.
I have a file from different code, that I should parse to use as my input.
A snippet from it looks like:
GLOBAL SYSTEM PARAMETER
NQ 2
NT 2
NM 2
IREL 3
*************************************
BEXT 0.00000000000000E+00
SEMICORE F
LLOYD F
NE 32 0
IBZINT 2
NKTAB 936
XC-POT VWN
SCF-ALG BROYDEN2
SCF-ITER 29
SCF-MIX 2.00000000000000E-01
SCF-TOL 1.00000000000000E-05
RMSAVV 2.11362995016878E-06
RMSAVB 1.25411205586140E-06
EF 7.27534671479201E-01
VMTZ -7.72451391270293E-01
*************************************
And so on.
Currently I am reading it line by line, as:
Program readpot
use iso_fortran_env
Implicit None
integer ::i,filestat,nq
character(len=120):: rdline
character(10)::key!,dimension(:),allocatable ::key
real,dimension(:),allocatable ::val
i=0
open(12,file="FeRh.pot_new",status="old")
readline:do
i=i+1
read(12,'(A)',iostat=filestat) rdline!(i)
if (filestat /= 0) then
if (filestat == iostat_end ) then
exit readline
else
write ( *, '( / "Error reading file: ", I0 )' ) filestat
stop
endif
end if
if (rdline(1:2)=="NQ") then
read(rdline(19:20),'(i)'),nq
write(*,*)nq
end if
end do readline
End Program readpot
So, I have to read every line, manually find the value column corresponding to the key, and write that(For brevity, I have shown for one value only).
My question is, is this the proper way of doing this? or there is other simpler way? Kindly let me know.
If the file has no variability you scarcely need to parse it at all. Let's suppose that you have declared variables for all the interesting data items in the file and that those variables have the names shown on the lines of the file. For example
INTEGER :: nq , nt, nm, irel
REAL:: scf_mix, scf_tol ! '-' not allowed in Fortran names
CHARACTER(len=48) :: label, text
LOGICAL :: semicore, lloyd
! Complete this as you wish
Then write a block of code like this
OPEN(12,file="FeRh.pot_new",status="old")
READ(12,*) ! Not interested in the 1st line
READ(12,*) label, nq
READ(12,*) label, nt
READ(12,*) label, nm
READ(12,*) label, irel
READ(12,*) ! Not interested in this line
READ(12,*) label, bext
READ(12,*) label, semicore
! Other lines to write
CLOSE(12)
Fortran's list-directed input understands blanks in lines to separate values. It will not read those blanks as part of a character variable. That behaviour can be changed but in your case you don't need to. Note that it will also understand the character F to mean .false. when read into a logical variable.
My code snippet just ignores the labels and lines of explanation. If you are of a nervous disposition you could process them, perhaps
IF (label/='NE') STOP
or whatever you wish.

Gdb Syntax for print command

How can I view the data at the address of the first operand in gdb?
cmp [ebp+eax], edi
I tried using:
print /d $ebp
print /d $eax
and manually adding the values to make the address, but was not sure what to do next, or if there was an easier way...
(gdb) help x
Examine memory: x/FMT ADDRESS.
ADDRESS is an expression for the memory address to examine.
FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
t(binary), f(float), a(address), i(instruction), c(char) and s(string).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
The specified number of objects of the specified size are printed
according to the format.
For your example:
x/d $ebp+$eax

Resources