Author Topic: In 8088/86 assembly, how do you use scasb?  (Read 5763 times)

Offline s0s

  • Jr. Member
  • *
  • Posts: 2
In 8088/86 assembly, how do you use scasb?
« on: June 18, 2017, 05:33:36 AM »
Hi,

Every result I found on this message board was for either 64-bit code, or used extended registers, which means it wasn't intended for the processor I'm using, which is the 8088. I'm trying to learn how to properly find the length of a string using the instruction with the mnemonic "scasb". I've tried this http://www.int80h.org/strlen/ and this https://www.csc.depauw.edu/~bhoward/asmtut/asmtut7.html but I can't get them to work. I've been trying to get my code to work on my regular computer with a modern CPU and Linux, before I try it on my 8088, because it's a lot easier to keep changing code and trying new things on this computer, however I keep getting a seg fault.

Maybe someone can point out where I'm going wrong:
Code: [Select]
section .data
msg db "Cowabunga", 0h ; Declare a NULL terminated string

section .text
global _start

_start:
mov ax, msg
mov di, ax ; Put the address of msg into DI

; mov ax, ds ; Make ES = DS
; mov es, ax

mov cx, 0xFFFF ; Initialize CX
sub al, al ; Initialize AL

cld
repne scasb

not cx ; Invert the value in CX
dec cx ; Subtract 1, now we have the string length

mov dx, 0x01 ; Number of bytes to print
add cx, 0x30 ; Convert the number to ASCII
mov bx, 1 ; Write to the STDOUT file
mov ax, 4 ; Invoke SYS_WRITE (kernel opcode 4)
int 80h

Thanks
« Last Edit: June 18, 2017, 05:37:37 AM by s0s »

Offline dreamCoder

  • Full Member
  • **
  • Posts: 107
Re: In 8088/86 assembly, how do you use scasb?
« Reply #1 on: June 18, 2017, 07:50:57 AM »
int 80h on 8088 CPUs?

so, there's a 16-bit Linux then?

You're mixing up too many things. Linux + DOS programming, 16-bit addressing on 32-bit CPUs etc. Don't just pick up any examples from the internet without knowing the background of such examples (Linux, DOS, WinAPI, 32-bit, 64-bit, 16-bit etc). In your case, you're attempting to program a 16-bit addressing examples (via SCASB) using 32-bit Linux operating system which uses 32-bit default addressing (SI,DI vs ESI,EDI). There's no such thing as 16-bit Linux that runs on 8088/86 processors. And I see traces of 16-bit int 21h usage (which is basically a DOS program) in "mov ax,msg" too!


 
 

 

Offline s0s

  • Jr. Member
  • *
  • Posts: 2
Re: In 8088/86 assembly, how do you use scasb?
« Reply #2 on: June 18, 2017, 08:53:39 AM »
int 80h on 8088 CPUs?

so, there's a 16-bit Linux then?
Although I stated I am only testing this on Linux, the answer to your second question is yes. I made it clear I'm trying to learn how to use scasb. Of course I would adapt it to the 8088 when I was writing a program for it!

You're mixing up too many things. Linux + DOS programming, 16-bit addressing on 32-bit CPUs etc. Don't just pick up any examples from the internet without knowing the background of such examples (Linux, DOS, WinAPI, 32-bit, 64-bit, 16-bit etc). In your case, you're attempting to program a 16-bit addressing examples (via SCASB) using 32-bit Linux operating system which uses 32-bit default addressing (SI,DI vs ESI,EDI). There's no such thing as 16-bit Linux that runs on 8088/86 processors. And I see traces of 16-bit int 21h usage (which is basically a DOS program) in "mov ax,msg" too!
While I want to thank you for pointing out that I was using 16-bit registers in this example, I don't understand how you think being condescending is helpful. While I certainly don't expect people to help me, I want to point out that I was being polite, and even showing that I was putting forth effort. While I likely have errors in my code, you addressed everything but the point of the topic, scasb, which seems intentional.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: In 8088/86 assembly, how do you use scasb?
« Reply #3 on: June 18, 2017, 09:31:50 AM »
Hi s0s,

Welcome to the Forum.

The funny thing is, your use of "repne scasb" is fine. Your problems are elsewhere.

You've got an 8088? Can you run Nasm on it? I think it will be hard (if possible) to find a version of Nasm that will run on an 8088. Best thing for this might be to put it in a glass case. If you really want to program for it, we might be able to help you.

If you want to program for a more modern machine, we can probably help you with that, too. Mixing them probably isn't going to work. What do you really want to do?

Best,
Frank