Author Topic: Why wouldnt this work?!  (Read 6030 times)

0 Members and 1 Guest are viewing this topic.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Why wouldnt this work?!
« on: August 13, 2012, 10:41:46 pm »
So this program creates a prgm which name is in str1, and puts memory (10 bytes) into that prgm.
Start:
Ld Hl, Str1Address
Rst 20h ( B_Call Mov9ToOp1)
Rst 10h ( B_Call ChkFindSym)
Ex De, HL
Ld C, (HL)
Inc HL
Ld B,(HL)
Inc HL
Ld De, Op1
Ld A,5
Ld (DE),A
Inc DE
Ldir
xor A
Ld (DE),A
B_Call ChkFindSym
Ld HL, 0
B_Call CreateProg
Push DE
Inc DE
Inc DE
Ld HL,10
B_Call InsertMem
Pop HL
Push HL
B_CALL LdHLind
Ld BC, 10
Add HL, BC
Ex DE, HL
Pop HL
Ld (HL),E
Inc HL
Ld (HL), D
Ldir
Ret

Str1Address:
db. StrngObj, tVarString, 00h,0
Please, dont optimize or anything. I want to see how it's working, and understand ASM Better.
I heard that OPs gets changed alot, but im not sure. Anyways, this Program does create a prgm, but it's not exactly the same as "string" inside Str1. So can you help me? Thank you :)
« Last Edit: August 14, 2012, 06:28:45 pm by TiAddict »

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Why wouldnt this work?!
« Reply #1 on: August 14, 2012, 12:16:28 am »
So wait, is this supposed to put the string you're assembling with in as the Program's contents in a basic editor? If so, I bet the problem is that you're confusing Strings (ASCII-ish) and tokens (not so ASCII-ish) That would garble some stuff, but not all. For instance, a space in ASCII is randM or something in prgm tokens, but I think all the uppercase letters are the same.

But I'm no good at real assembly.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: Why wouldnt this work?!
« Reply #2 on: August 14, 2012, 01:43:11 am »
So this program is suppose to MAKE a program where, the name is in String1. And to THAT program (name from str1), i want to put in 10 bytes. and no there's no problem with that! :(

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Why wouldnt this work?!
« Reply #3 on: August 15, 2012, 05:16:57 pm »
Quick question: When you say 'not working' could you clarify? Does it crash? Does it get the characters mixed up? Does it do absolutely nothing? That would help diagnose what is actually happening.

Oh, and keep in mind str1 is stored in tokens, not ASCII.
« Last Edit: August 15, 2012, 05:17:51 pm by willrandship »

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Why wouldnt this work?!
« Reply #4 on: August 17, 2012, 11:48:58 am »
I don't think you ever load the name stored inside the string. Try something like this (based off your code):
Code: [Select]
Start:
ld hl,Str1Address
rst 20h ;( B_Call Mov9ToOp1)
rst 10h ;( B_Call ChkFindSym)
ret c
inc de ;skip size bytes
inc de
ex de,hl
ld bc,8 ;copy up to 8 bytes of the string for program name
ld de,stringName+1 ;store the program name at stringName+1 (so as not to overwrite ProgObj)
ldir
ld hl,stringName ;start of program name
rst 20h ;put into OP1
ld hl,10 ;10 bytes of (random) data
B_Call _CreateProg
ret

Str1Address:
.db StrngObj, tVarStrng, 0

stringName:
.db ProgObj,"        "

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Why wouldnt this work?!
« Reply #5 on: August 17, 2012, 11:56:21 am »
chickendude, I'm not so sure that would work, because program names need to be null-terminated but strings are not. You might end up creating a program with its name including the size bytes and some data of the next variable. In this case, you will need to read the size bytes of the string and ldir based on that, then null-terminate manually. (You might be able to avoid manual null-termination if the destination buffer is already filled with null bytes.)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Why wouldnt this work?!
« Reply #6 on: August 17, 2012, 12:16:10 pm »
I remember reading that a program name needs to be either 8 characters or null-terminated. Instead of filling the name buffer with spaces i suppose you could just fill it with eight 0's.

EDIT: Ah but you're right, since the entire buffer is overwritten with the ldir anyway. So yeah, it'd be best to read the size of the string and only load that many characters.
« Last Edit: August 17, 2012, 12:18:36 pm by chickendude »