Assembly MOV doesn't work, Debug for Linux and INT code list - linux

I have a problem here...
I'm using debug (in cmd/ms-dos) to learn some things and to peforme some commands... I set AX to 1234 and DX to ABCD.
So, I did '-a 100' to register a instruction, I did: mov ah,dl
And them "-g" (because I set an interruption) or "-g 102" to peforme the instruction and stop before 102 offset (if I not set the interruption).
When I peform -r to show me the registers values, they remain unchanged, this should be AX:CD34, but AX is 1234 yet, looks like the MOV command doesn't works... what am I doing wrong?
http://img203.imageshack.us/img203/4866/movdxdldoesntworks.png
(sorry for the link, I need reputation to post image)
I also would like to know if exists something like Windows Debug to Linux, I mean, I have nasm and yasm in my Linux installation (Debian-based), but it's just a compiler, I need to write the code into a file, and compile it to run, we have some "emulator" or "debug" tool for ASM in Linux? Like the Debug windows software in the picture above?
The last thing, sorry to make the message so long with 3 questions, but I don't want to "flood" with a lot of topics, so, my last question is where can I find some kind of list of interruptions? I would like to find some list or manual with machine code functions. In Peter Norton's book, for example, when I have "02h" in the "AH" register, I tell to DOS to print one character in the screen, and he said "if you want to find a list of functions, you can look your DOS manual", well, I can't find this dos manual (in linux we can type "man" and we have manuals for everything), the windows "help" function is only a list for simple commands, not a real manual like the unix "man".
I try to find it in google, but every "DOS manual" did I found only show me simple functions like "cd, dir, format, time, blablabla", nothing real technical about the system or something... Can you help-me in find some complete list of "AH" commands and functions?
I know INT 18h is for run Basic and INT 19h restarts the computer (a guy said to me, 18h for him doesn't run basic but restarts the computer instead of INT 19h). I also find 2 or 3 more occurrences in Google, but not a "complete" list, someone have it?
Thanks for the help, patience and attention, I love you! ;)

Please try it again with:
.g=cs:0100 0102
http://www.armory.com/~rstevew/Public/Tutor/Debug/debug-manual.html
.........
RBIL: Ralf Browns x86/MSDOS Interrupt List
http://www.pobox.com/~ralf
http://www.pobox.com/~ralf/files.html
ftp://ftp.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/
Dirk

It is hard to say why it does not work in your debugger.
Did you try to just type this in your program and put breakpoint at the end of it to see the result?
Here is an answer to the question about linux debugger (they recommend GDB):
Linux Assembly Debugger
For the third question here you have a good source of info about interrupts: http://www.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/WWW/files.html
In case link gets outdated search for "Ralf Brown's Interrupt List"

Related

NASM - suppress segment base warnings for 64 bit code

I'm talking about this things:
warning: ds segment base generated, but will be ignored in 64-bit mode
I know that -w option can be used to suppress warnings in NASM, but from the list of warnings showed by the help menu nothing fits this type of warning. And -w-all gets rid of everything, except this.
Any way of doing this?
Since that particular error doesn't seem to be one of the suppressible ones (as you've stated, I'd just use sed as a post-processing step, piping the output through something like:
sed '/^warning: .. segment base generated, but will be ignored in 64-bit mode$/d'
Even if you're using nasm on Windows, you can still get the GNUWin32 port of sed to do the job.
And before you complain about this being a kludge, you should know that some of my greatest achievements were kludges, and many of them have out-lived my more well-designed code.
:-)

'modifying' an exe by working with bas using visbasic or q basic

all!
I'm trying to run programs to control stepper motors. The PC and software and stepper motor controller I have already in place are pretty old and I'm new to almost everything I'm doing here-learning as I go sort of thing. I've 'coded' a bit in Matlab, so I have a very basic level of coding logic, but basically no knowledge of any common syntax. So, I know some about the steppers and the stepper controller, but not much else!
I have a program called "Hoop.exe" that I'm trying to modify to slow down the speed of one of the steppers (I just need to change a 300 to a 200!) when I run the program. There is also an associated (assuming) hoop.bas and a hoop.txt file on the floppy disc. From looking at the txt file, it looks like basic code from examples of basic I've seen. I'm working with visual basic 2.0 and qbasic 1.1 on Windows 98.
So, I tried opening the hoop.bas file first with qbasic and with vb. With qb, I get a 'bad file mode' message. With vb, I get 'invalid file format' and it seems it wants me to open a mak file but I have no 'hoop.mak'. I did this thinking that I could open the bas file with vb or qb, and then edit it, and then save it as an exe, and then run that.
I found a pdf that showed how to incorporate a qb file into the command button of vb, and I tried that. But, I got an "Expected: end of statement" error in the first line! when I tried to save it as an exe.
So, all I really want to do is change my hoop.exe. I would assume that since qb and vb are both on the PC, one of them wrote the bas (maybe not!), so I'm wondering why neither of them can read it.
I've never used vb or qb, but if I have to get into the nitty gritty, it seems like I'd rather use qbasic, since I've never used a graphical interface to code before. But, is either one of those necessary in order to do what I want to do? (I'm going to need to write some programs to control these steppers when all is said and done, but I figured that I should take it one step at a time.)
I tried some form of copying and pasting into qb, but I couldn't immediately figure out how to do that. (Probably because I have no idea how to use qb.)
So, what would be the most efficient way to modify my hoop program?
If the answer is that I just need to learn basic with qb, that's fine, but I'd like to get some sort of indication from people who know what they're talking about before I put that much effort in.
I would really appreciate any pointers because I'm apparently completely clueless on my own!
8/10/2013:
Just in case it's helpful, here are some lines from the Hoop.txt I opened:
10 CLS : CLEAR 1000: P = 512
20 LOCATE , , 1
100 A% = INKEY$: PRINT A$;
105 IF A$ = "*" THEN GOTO 700
110 GOSUB 510: GOSUB 610: GOTO 100
500 REM
510 IF A$ = "" THEN RETURN
etc. This is the beginning of the interface code that allows me to talk to the motor controller
QuickBASIC and Visual Basic are very different, despite their common name of "BASIC" and despite the fact they were both made by Microsoft. First you need to determine if the .BAS file is QuickBASIC or Visual Basic. A simple quick way (though not the most accurate) is to open the file up in Notepad or some other text editor. If keywords such as "OPEN" or "LEN" or "MID" or "CLOSE" are in uppercase, then its more likely a QuickBASIC file. If the keywords look more like "Open" or "Close" or "Len" or "Mid", then its more likely a Visual Basic file.
Now keep in mind that there are other versions of BASIC that have been developed, such as Turbo BASIC (Borland's version) or GW-BASIC or BasicA or PowerBASIC and even Color Basic.
Now if you can't figure it out this way, the next thing I'd suggest is downloading a hex editor, such as XVI32 (though there are many other free ones out there). Look through the file (especially towards the end of the file) and there are usually signs that indicate what kind of compiler was used. You might see the words "Microsoft Basic Compiler" or "Borland Turbo Compiler". Usually towards the end of the file, there are string "stubs" put in by the compiler or linker that you can use to determine the compiler.
If all that fails and you are desperate and that "300" number is hard coded in the program and you need to change it, then there is another way to do this. First back up your original exe file. Then Use XVI32 or some other hex editor and search for the string "2c01" (300 is 012c hex and you need to reverse the 01 and 2c since Intel machines are little-endian). Once you find an instance of 2c01, change it to "c800" (200 is 00c8. Little Endian version would be c800). Save the file, then rerun it. This is a gruesome trial and error way to fix this. If it was changed from 300 to 200, then everything is good! If not, restore from your backup and try again!
Have you considered getting an Arduino or some other low cost and friendly electronics development platform? I think it would be the way to go for you to control stepper motors...
take a look:
http://arduino.cc/en/Tutorial/StepperUnipolar
If you google around you'll find tons of you tube videos showing off some arduino controlled stuff.
Modifying your current .exe seems to me a too long and hard path to follow instead of making your own and proper source code for achieving what you want, as you would need to disassemble the executable file and literally "know what you're doing" with all that assembly language to find where to patch the binary with the right value.
Anyway, if you post a picture or a schematic of your old hardware I could try to help you a little more, but I guess that would be better suited to this other stack exchange site:
http://electronics.stackexchange.com

Intro guide to troubleshooting errors in clisp

I'm new to lisp, working in clisp on cygwin. When I have a problem, I see something like this
*** - SYSTEM::READ-EVAL-PRINT: variable DB.CLISP has no value
The following restarts are available:
USE-VALUE :R1 Input a value to be used instead of DB.CLISP.
STORE-VALUE :R2 Input a new value for DB.CLISP.
ABORT :R3 Abort main loop
Break 1 [4]
And I have a bunch of prompts where the number seems to increment no matter what I do.
Can someone point me to a newbie guide to what this does, and what I can do here? I've found a few things but they are opaque to me. My practice now is just to quit out of clisp.
Did you take look at clisp faq list?
It has a question you are asking: How do I get out of the debugger?, although it links to the wrong section of the manual, what you are looking for is Top Level Loop.
Basically, "abort" reduces the debug level by 1 and "quit" drops you out of all the debuggers.

Ubuntu terminal in windows ? Can anyone explain the 'col' command in plain English for me?

Next week I am getting an exam on using basic commands and shell scripting using terminal in Ubuntu. Please help me out with two quick questions:
-Does a practice environment for the Ubuntu terminal exist? I don't want to dual boot with Linux, so I want to find somewhere I could practice using some basic terminal commands as Cygwin seems to be quite different from the ubuntu terminal.
-What does the col command in Linux do? The manual page is here: Link, but I find that hard to understand, and since it doesn't work in Cygwin, it's hard to interpret! Also, why would one use man piped to col -b -x?
Thank you very much and sorry for the probably silly questions!
You can use the Ubuntu LiveCD boot (boots up an Ubuntu system without actually installing it) and experiment with the Ubuntu terminal shell. Its actually the same CD as the standard Ubuntu installtion CD... you just chose "Try Ubuntu" instead of "Install Ubuntu" once it boots up:
https://help.ubuntu.com/community/LiveCD
col is program to filter out reverse-linefeeds (i.e. the backspace character) from text input. In the olden days of line printers, a common method to achieve boldface print was to print a character, then print a backspace character, then print the character again. This would make the printer strike the character twice in the same place. Some programs would emit text files formatted in this way (man is one such program)-- but if you then tried to display that text file to your terminal screen, you might end up seeing something like this: "here is b^Hbo^Hol^Hld^Hd text".
col -b simply filters text input to strip out those extra backspace and double-strike characters. The -x option converts tab characters to space characters, which might be useful if the output was formatted for a device with a particular tab width, but then displayed on a different device.
man pages often have the backspace/double-strike text embedded in them, so man piped into col was often useful.
Nowadays, most terminal emulators actually know how to handle the backspace/double-strike, so col doesn't get used as much.
Far better (easier to use, install, maintain, etc.) than Cygwin, and perhaps less resource-using than a virtual machine, is http://andlinux.org . That will give you a shell on your Windows desktop, and you can play with the col command to better understand it.
Win-bash is essentially the same shell as linux, but on windows. You can use this to experiment outside Linux but I'm not sure how effective it is.
Other options are virtual machines, and if you don't mind a reboot, you can install ubuntu with wubi which means it can be deleted from windows' add/remove programs when you are done with it. (Or just use the live disc)
Col has very limited use for most people, it only affects programs that write lines asynchronously as opposed to line by line...

Show last command with up arrow on a linux c shell

I have implemented a simple linux shell in c. Now, I am adding some features and one I immediately thought about was to be able to show the last commands with the up arrow.
Question 1:
However, I have no idea how to accomplish this. Do you?
Question 2:
Any comment on how to store the "history" commands are also appreciated. I suppose something like a queue which allows access to all elements would be a good idea. Am I wrong? Do I have to implement it or is there already some good implementation out there I should know about?
Thanks.
Build libedit or readline support into your shell.
If you want to be lazy, you can use rlwrap:
rlwrap prog
I wrote the shell for HelenOS. Grab the bzr repo and navigate to uspace/app/bdsh (bdsh stands for the (b)rain (d)ead (sh)ell).
Other contributors have since added line editing / history / tab completion to the functions that handle input. Its written purely in ANSI C, does not link against glibc and implements its own functions. The code (both in the shell and underlying HelenOS libc) is 3 clause BSD, you can use it in anything.
If nothing else, it might help to just examine the implementation to get started.

Resources