I have some problems with masm - windows

I have some problems with masm when I want to run:
CSEG segment
org 100h
Begin:
mov ah, 9
mov dx, offset Message
int 21h
;mov ah, 9
;mov dx, offset mess2
;int 21h
int 20h
mess2 db 'It is me$'
Message db 'Hello, World2243!$'
CSEG ends
end Begin
It prints:
Smth like: ||=It's me!
But I commented this string out!!
I compile this code on DosBox, maybe that's the cause

As already mentioned, you use tasm, not masm. These are two different things, see tasm and masm
In order to print two lines, I used the code:
MODEL TINY
STACK 100h
DATASEG
Hellostr DB 'Hello First Step Site $'
str2 DB 'Step 16 $'
CODESEG
start:
mov ax,#data
mov ds,ax
mov dx,offset Hellostr
mov ah,09h
int 21h
mov dx,offset str2
mov ah,09h
int 21h
mov ah,04Ch
mov al,1h
int 21h
end start
compile + build + run:
mount c C:\path\to\asm\file\PROGRA~1.asm
c:
tasm PROGRA~1.asm
tlink /3 PROGRA~1.obj
PROGRA~1.exe
result:link
I will also note, as indicated in the screenshot above, I have a dosbox version 0.74-3
And lastly: I advise you to look VERY carefully at the screenshot you provided.

Related

Getting error after copying 8086 code from book

I am having troubles running this 8086 programs that take one letter input from keyboard and outputs "the letter you typed is _"
I just started reading my college book on this and trying to run some code from the book on my computer but got stuck here.
The code below is from my college book.
I am running it in emu8086 emulator.
CODE SEGMENT
; set the DS register
MOV AX, DATA
MOV DS, AX
; Read Keyboard
MOV AH, 08H
INT 21H
; Save input
MOV BL, AL
; Display first part of Message
MOV AH, 09H
MOV DX, OFFSET MESSAGE
INT 21H
; Display character of BL register
MOV AH, 02H
MOV DL, BL
INT 21H
; Exit to DOS
MOV AX, 4C00H
INT 21H
CODE ENDS
DATA SEGMENT
MESSAGE DB “The letter you typed is $”
DATA ENDS
END
The error I am getting is
INT 21h, AH=09h -
address: 00020
byte 24h not found after 2000 bytes.
; correct example of INT 21h/9h:
mov dx, offset msg
mov ah, 9
int 21h
ret
msg db "Hello$"
After further debugging by myself I have concluded there is some problem with this
MOV AX, DATA
MOV DS, AX
If I remove it from my code it executes but with some garbage in the start.
Any suggestions will be appreciated.
Update:
Image of emulator around the string "the letter you typed $"
umm so after giving up for 2 days I referenced another book, and in there they weren't using segments. So I removed segments and the program ran flawlessly here is the new code:
ORG 100H
MOV AH, 08H ; Read Keyboard
INT 21H
MOV BL, AL ; Save input
MOV AH, 09H ; Display first part of Message
MOV DX, OFFSET MESSAGE
INT 21H
MOV AH, 02H ; Display character of BL register
MOV DL, BL
INT 21H
MOV AX, 4C00H ; Exit to DOS
INT 21H
RET
MESSAGE DB "The letter you typed is $"
Thank you to everyone who tried to help me, really appreciated.

No output from 8086 program when running ml program.asm in DOSBox

I got this code from the Geeks-for-Geeks site, but there were lots of indentation errors, I changed the code to the following but, when running the code using MASM and DOSBox it's giving no output.
The Output I should get, According to the site I should get 20 but I get nothing, the code is saved as pro.asm, and I'm using DOSBox version 0.74.
For getting the o/p in the DOSBox I did,
mount c c:\8086
c:
ml pro.asm
Code:
;8086 program to convert a 16-bit decimal number to octal
.MODEL SMALL
.STACK 100H
.DATA
d1 dw 16
.CODE
MAIN PROC FAR
MOV ax,#DATA
MOV ds,ax
;load the value stored in variable d1
MOV ax, d1
;convert the value to octal
;print the value
CALL PRINT
;interrupt to exit
MOV AH,4CH
INT 21H
MAIN ENDP
PRINT PROC
;initialize count
MOV cx,0
MOV dx,0
label1: ;if ax is zero
cmp ax,0
je print1
;initialize bx to 8
mov bx, 8
;divide it by 8 to convert it to octal
div bx
;push it in the stack
push dx
;increment the count
inc cx
;set dx to 0
xor dx,dx
jmp label1
print1: ;check if count is greater than zero
cmp cx,0
je exit
;pop the top of stack
pop dx
;add 48 so that it
;represents the ASCII
;value of digits
add dx,48
;interrupt to print a
;character
mov ah,02h
int 21h
;decrease the count
dec cx
jmp print1
exit : ret
PRINT ENDP
END MAIN
The output I'm getting can be seen below
Your code looks okay. Your screenshot shows you have only assembled and linked the code but not actually run it. To run it type:
pro.exe

Printing individual characters from a string to standard output in ms-dos/assembly x86-16

I am new to x86-16bit programming. I am very stumped by how I call function 2 properly to read characters individually from a string. If anybody has any ideas it would be greatly appreciated. The code below shows my current attempt (one of many).
.model small
.data
message db "Hello, DOS Here!", 0dh, 0ah
.code
main proc
mov ax, #data
mov ds, ax
L1:
mov ah, 2
mov bx, 1
int 21h
loop L1
.EXIT
main endp
end main
I'm also supposed to use push and pop to be able to print the string in the same method but backwards. I'm sure I'm missing something obvious. All I get when it prints is the British pound symbol for a few lines.
(Dec: 156; Hex: 9C)
With this definition message db "Hello, DOS Here!", 0dh, 0ah, next code will print the complete message:
mov ah, 02h
mov dl, message ;Get the H character
int 21h
mov dl, message+1 ;Get the e character
int 21h
mov dl, message+2
int 21h
mov dl, message+3
int 21h
mov dl, message+4
int 21h
mov dl, message+5
int 21h
mov dl, message+6
int 21h
mov dl, message+7
int 21h
mov dl, message+8
int 21h
mov dl, message+9
int 21h
mov dl, message+10
int 21h
mov dl, message+11
int 21h
mov dl, message+12
int 21h
mov dl, message+13
int 21h
mov dl, message+14
int 21h
mov dl, message+15
int 21h
mov dl, message+16 ;Get the 0Dh carriage return
int 21h
mov dl, message+17 ;Get the 0Ah linefeed
int 21h
Rather stupid, wouldn't you say?
In order to use a loop and obtain much compacter code we need to:
Put the address of your message in an address register. You can choose from SI, DI, BX and BP. I've picked BX in below code.
Read one byte at this address.
Output the byte with DOS.
Increment the pointer in the address register.
Repeat steps 2, 3, 4, 5 for all the text by checking if it was the linefeed character that you just outputted. Since in your text that's the very last character.
A version of this loop:
mov bx, OFFSET message ;1.
Again:
mov dl, [bx] ;2.
mov ah, 02h ;3.
int 21h
inc bx ;4.
cmp dl, 0Ah ;5.
jne Again
I'm also supposed to use push and pop to be able to print the string in the same method but backwards.
To accomplish this next task of yours, you would put a push dx in between steps 2. and 3. Then write an additional loop to display the reversed string:
Again2:
pop dx
mov ah, 02h
int 21h
cmp dl, "H"
jne Again2
The pitfalls here will be that
you shouldn't output the linefeed and carriage return before the other (real) characters ==> Hint: do 2 pops before starting the 2nd loop
you can't readily assume that "H" will only appear as the text's first character ==> Hint: count the number of pushs
Caveat: I haven't done this in decades and I don't have a compiler in front of me that can do this. This looks like an assignment so I'm not going to write the code, but I'll point you in the right direction.
Int 21h function 2 requires you to set dl equal to the character you want to output. No pushes and pops required here since DOS doesn't use the stack for parameter passing. First, outside of your loop, you want to point a register to the address of the message, something like: MOV si, message. Then, you need to dereference a single byte from the message and put it into dl. This will require using indirect address notation. Then you can call interrupt 21h and write the character.
As for the loop, there are a few ways to approach it. You could use a counter, with cx being the typical register for that, and use a LOOP statement or DEC and JNZ statements. Or you could put a marker at the end of the string, and terminate the loop when you hit that marker. A null character is commonly used for this. You will also need to move to the next character in the string. You can do that by adding an index, or by incrementing the value of the si register each iteration of the loop. Something like INC si
With all that said, there is a much easier way that avoids the loop but maybe it is cheating. Take a look at interrupt 21h function 9
Yeah, using function 9 would be 'cheating' as it is one of the other exercises (which was the easy one). I have revised my code and got it to start with the beginning character. I just need to figure out how to get it to keep looping so that it continues to read the string and not stop arbitrarily. Here's what I've got so far (It prints H and the 15 e's):
.model small
.data
message db "Hello, DOS Here!"
.code
main proc
mov ax, #data
mov ds, ax
mov ah, 2
mov cx, 16
mov dl, message
L1:
int 21h
mov dl, message + 1
loop L1
.EXIT
main endp
end main

MASM, address 9ffffh

i have some strange things.
Here is example of code.
CODESEGMENT segment
assume CS: CODESEGMENT, DS: CODESEGMENT, SS: NOTHING, ES:NOTHING
org 100h
BEGIN: mov AX, 9fffh
mov DS, AX
mov CX, DS:000FH
;-----------------------------------------------------
;End of program, exit to DOS
;-----------------------------------------------------
mov AX, 4c00h
int 21h
CODESEGMENT ends
end BEGIN
and this code
CODESEGMENT segment
assume CS: CODESEGMENT, DS: CODESEGMENT, SS: NOTHING, ES:NOTHING
org 100h
BEGIN: mov AX, 9000h
mov DS, AX
mov BX, [0FFFFH]
;-----------------------------------------------------
;End of program, exit to DOS
;-----------------------------------------------------
mov AX, 4c00h
int 21h
CODESEGMENT ends
end BEGIN
I think that when i get offset from DS i have, for example this,
DS = 9000h
offset = FFFFh
DS = 9000h * 10h = 90000h
+
0FFFFh
=
9FFFFh
Thinking this way i wrote this two codes.
And i thought this codes did the same thing - reading to CX two bytes from address 9FFFFh, but i looked in masm debugger (afd) and understood that i was wrong.
First code:
Second code
I use masm because i'm student, and i get used to it.
Please can some tell me where is my mistake.

reading from File in assembly

i am trying to read a username and a password from a file in x86 assembly for the perpose of authentication
obviously the file consists of two lines , the user name and the password how can i read the two lines seperately and compare them?
My attempt:
proc read_file
mov ah,3dh
lea dx,file_name
int 21h
mov bx, ax
xor si,si
repeat:
mov ah, 3fh
lea dx, buffer
mov cx, 100
int 21h
mov si, ax
mov buffer[si], '$'
mov ah, 09h
int 21h ;print on screen
cmp si, 100
je repeat
jmp stop;jump to end
stop:
RET
read_file ENDP
Go here and read up on functions like CreateFile and ReadFile.
You should use system class to do that and it depends on whether you use Windows or Linux.
Check this : http://www.freebsd.org/doc/en/books/developers-handbook/x86-system-calls.html

Resources